时间操作:
clock_t clock ( void ); 返回自程序运行以来
double difftime ( time_t time2, time_t time1 );返回时间差秒,time2要大于time1
time_t mktime ( struct tm * timeptr );转换tm至time_t
time_t time ( time_t * timer );返回自1970后的秒数,timer可为NULL,为保存时间用
时间格式化:
char * asctime ( const struct tm * timeptr );按格式“Www Mmm dd hh:mm:ss yyyy”,末尾有\n,例如:“Sat May 20 15:21:51 2000”
char * ctime ( const time_t * timer );同上,只不过是time_t
struct tm * gmtime ( const time_t * timer );返回转换至UTC时间
struct tm * localtime ( const time_t * timer );返回转换至当前时间
size_t strftime ( char * ptr, size_t maxsize, const char * format, const struct tm * timeptr );
format列表:
%a Abbreviated weekday name * Thu
%A Full weekday name * Thursday
%b Abbreviated month name * Aug
%B Full month name * August
%c Date and time representation * Thu Aug 23 14:55:02 2001
%d Day of the month (01-31) 23
%H Hour in 24h format (00-23) 14
%I Hour in 12h format (01-12) 02
%j Day of the year (001-366) 235
%m Month as a decimal number (01-12) 08
%M Minute (00-59) 55
%p AM or PM designation PM
%S Second (00-61) 02
%U Week number with the first Sunday as the first day of week one (00-53) 33
%w Weekday as a decimal number with Sunday as 0 (0-6) 4
%W Week number with the first Monday as the first day of week one (00-53) 34
%x Date representation * 08/23/01
%X Time representation * 14:55:02
%y Year, last two digits (00-99) 01
%Y Year 2001
%Z Timezone name or abbreviation CDT
%% A % sign %
宏:
CLOCKS_PER_SEC表示每秒有多少个clock tickets
类型:
clock_t 由clock函数返回,运行整数运算
time_t时间戳,1970后的秒数
struct tm日历时间,包括以下字段:
int tm_sec; 0-61*,某些系统上会超出
int tm_min; 0-59
int tm_hour; 0-23
int tm_mday; 1-31
int tm_mon; 0-11
int tm_year; years since 1900
int tm_wday; 0-6
int tm_yday; 0-365
int tm_isdst;