#include <time.h> #include <stdio.h> int main() { struct tm *tm_ptr; time_t the_time; (void) time(&the_time); tm_ptr=gmtime(&the_time); printf("Raw time is %ld\n",the_time); printf("gmtime gives:\n"); printf("date: %02d/%02d/%02d\n", tm_ptr->tm_year,tm_ptr->tm_mon+1,tm_ptr->tm_mday); printf("time: %02d:%02d:%02d\n", tm_ptr->tm_hour,tm_ptr->tm_min,tm_ptr->tm_sec); return 0; }
函数原型:
#include <time.h>
struct tm *gmtime(const time_t timeval);
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(0代表一月)
int tm_year;从1900年开始计算的年份(今年就是112)
int tm_wday;星期几,0-6(0代表周日)
int tm_uday;年份中的日期,0-356
int tm_isdst;日否为夏日制