clock : 시간 계산 함수
difftime : 두 시간 사이의 차이 계산
mktime : structtm 구조체를통해epoch time을구해내는함수
time : 현재 시간
asctime : 시간구조체를 문자로 변환
ctime : 시간변수를 문자로 변환
gmtime : UTC 시간으로 변환
localtime : 지역 시간으로 변환
strftime : 날짜와시간으로이루어진문자열을structtm으로변환
2. 라이브러리 변수
size_t : 부호 없는 정수형
clock_t : 프로세서 시간 저장 변수 타입
time_t : 캘린더 시간 저장 변수 타입
struct tm : 날짜, 시간 처리 구조체
struct tm {
int tm_sec; /* seconds, range 0 to 59 */
int tm_min; /* minutes, range 0 to 59 */
int tm_hour; /* hours, range 0 to 23 */
int tm_mday; /* day of the month, range 1 to 31 */
int tm_mon; /* month, range 0 to 11 */
int tm_year; /* The number of years since 1900 */
int tm_wday; /* day of the week, range 0 to 6 */
int tm_yday; /* day in the year, range 0 to 365 */
int tm_isdst; /* daylight saving time */
};
3. 관련 용어
Epoch Time : 1970년 01월 01일 00시 00분 00초를 기점으로 흐르는 시간
UTC 타입(Coordinated Universal Time) : 영국그리니치천문대(경도0)를기준으로하는세 표준시간대
UTC+9 : 한국 시간
Greenwich Mean Time, GMT : 영국 런던을 기점, 뉴질랜드 웰링턴을 종점으로 하는 협정 세계시
int main ()
{
time_t start,end;
char szInput [256];
double dif;
time (&start);
printf (“Please, enter your name: ”);
gets (szInput);
time (&end);
dif = difftime (end,start);
printf (“Hi %s.\n”, szInput);
printf (“It took you %.2lf seconds to type your name.\n”, dif );
return 0;
}
%a 요일 이름의 약자
%M 분(00-59)
%A 요일 이름
%p AM 또는 PM
%b 월 이름의 약자
%S 초(00-59)
%B 월 이름
%w 요일(0-6)
%c 지역 날짜와 시간
%x 지역 날짜
%d 날짜(01-31)
%X 지역 시간
%H 시간(00-23)
%y 연도(00-99)
%l(엘) 시간(01-12)
%Y 연도(예, 2003)
%j 1월 1일 이후의 날짜(001-366)
%% 퍼센트 기호(%)
%m 월(01-12)
#include
#include
int main ()
{
time_t rawtime;
struct tm * timeinfo;
char buffer [80];
time (&rawtime);
timeinfo = localtime (&rawtime);
strftime (buffer,80, “Now it's %I:%M%p.”,timeinfo);
puts (buffer);
return 0;
}
//결과값
Now it's 03:21PM.