struct tm
struct tm {
int tm_sec; /*代表目前秒数,正常范围为0-59,但允许至61秒 */
int tm_min; /*代表目前分数,范围0-59*/
int tm_hour; /*从午夜算起的时数,范围为0-23*/
int tm_mday; /*目前月份的日数,范围01-31*/
int tm_mon; /*代表目前月份,从一月算起,范围从0-11*/
int tm_year; /*从1900 年算起至今的年数*/
int tm_wday; /*一星期的日数,从星期一算起,范围为0-6 */
int tm_yday; /*从今年1月1日算起至今的天数,范围为0-365*/
int tm_isdst; /*日光节约时间的旗标*/
};
time()
#include
#include
#include
int main(void)
{
time_t timer;//time_t就是long int 类型
struct tm *tblock;
timer = time(NULL);//这一句也可以改成time(&timer);
tblock = localtime(&timer);
printf("Local time is: %s\n",asctime(tblock));
return 0;
}
#include
#include
int main()
{
struct tm *t;
time_t tt;
time(&tt);
t=localtime(&tt);
printf("%4d年%02d月%02d日 %02d:%02d:%02d\n",t->tm_year+1900,t->tm_mon+1,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec);
return 0;
}
gmtime()
#include "stdio.h"
#include "time.h"
#include "stdlib.h"
int main(void)
{
time_t t;
struct tm *gmt, *area;
tzset(); /* tzset()*/
t = time(NULL);
area = localtime(&t);
printf("Local time is: %s", asctime(area));
gmt = gmtime(&t);
printf("GMT is: %s", asctime(gmt));
return 0;
}