|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include "time.h"
#include<stdio.h>
#include<string.h>
int main(int argc, char* argv[])
{
struct tm* tm0;
time_t time_t0 = 0;
tm0 = localtime(&time_t0);
printf("%d %d %d %d %d %d %d %d %d %ld %s\n",tm0->tm_sec,tm0->tm_min,tm0->tm_hour,tm0->tm_mday,tm0->tm_mon,tm0->tm_year,tm0->tm_wday,tm0->tm_yday,tm0->tm_isdst,tm0->tm_gmtoff,tm0->tm_zone);
printf("当前时间 = %s", ctime(&time_t0));
time_t timer;
struct tm *tml,*tmb;
timer = time(NULL);
printf("\ntimer = %d\n",timer);
printf("当前时间 = %s", ctime(&timer));
tml = localtime(&timer);
printf("%d %d %d %d %d %d %d %d %d %ld %s \n",tml->tm_sec,tml->tm_min,tml->tm_hour,tml->tm_mday,tml->tm_mon,tml->tm_year,tml->tm_wday,tml->tm_yday,tml->tm_isdst,tml->tm_gmtoff,tml->tm_zone);
tmb = gmtime(&timer);
printf("%d %d %d %d %d %d %d %d %d %ld %s \n",tmb->tm_sec,tmb->tm_min,tmb->tm_hour,tmb->tm_mday,tmb->tm_mon,tmb->tm_year,tmb->tm_wday,tmb->tm_yday,tmb->tm_isdst,tmb->tm_gmtoff,tmb->tm_zone);
time_t timel,timeb;
timel = mktime(tml);
printf("\ntimel = %d\n",timel);
printf("当前时间 = %s", ctime(&timel));
timeb = mktime(tmb);
printf("timeb = %d\n",timeb);
printf("当前时间 = %s", ctime(&timeb));
return 0;
}
打印信息
0 0 8 1 0 70 4 0 0 28800 CST
当前时间 = Thu Jan 1 08:00:00 1970
timer = 1655191694
当前时间 = Tue Jun 14 15:28:14 2022
14 28 15 14 5 122 2 164 0 28800 CST
14 28 7 14 5 122 2 164 0 0 GMT
timel = 1655162894
当前时间 = Tue Jun 14 07:28:14 2022
timeb = 1655162894
当前时间 = Tue Jun 14 07:28:14 2022
请问 为什么 localtime和 gmtime 在mktime函数执行之后 返回的S数 是一样的
|
|