typedef long time_t;//日历时间
struct tm{
int tm_sec;/*seconds after the minute:[0,60]*/
int tm_min;/*minutes after the hour:[0,59]*/
int tm_hour;/*hours after midnight:[0,23]*/
int tm_mdaty;/*day of month:[1,31];
int tm_mon;/*months since January[0,11]*/
int tm_year;/*years since 1900*/
int tm_wday;/*days since Sunday:[0,6]*/
int tm_yday;/*days since 1 January*/
int tm_isdst;
time_t time(time_t *tp)// 返回当前的日历时间(从1970年1月1日以来的秒数),若tp不为NULL也把该值存入tp所指的对象中
char *ctime(const time_*t_ptr) 把t_ptr所指向的日历时间转为系统提供的串
char *asctime(const struct tm*tp) 把tp指向的分解时间转化为系统提供的串
double difftime(time_t t0,time_t t1);计算t1-t0
struct tm*gmtime(const time_t *tpr);将time_t转化为struct tm//格林威治时间
struct tm*localtime(const time_t *tpr);将time_t转化为struct tm//当地时间
time_t mktime(struct tm*tp);//把tp所指的时间转化为相应的日历时间,函数忽略tm_wday,tm_tday的值
//计算离当前时间很好的函数
例如:
struct tm *tp;
time_t now,later;
now=time(NULL);
tp=localtime(&now);
tp->tm_mday+=1000;
later=mktime(tp);
printf("/n1000 days from now: %s/n",ctime(&later));
size_t strftime(char *s,size_t n,const char *cntrl_str,const struct tm *tp)//由cntrl_str指向的控制串指导下,把字符指向写入有s指向的串中如:
char s[100];
time_t now;
now=time(NULL);
strftime(s,100,"%H:%M%S on %A,%d %B %Y,localtime(&now));
printf("%s/n/n",s);
如会显示:13:01:15 on Tuesday,19 January 2010