localtime()为不同的输入时间戳提供相同的输出

时间:2018-01-08 04:14:14

标签: c

有人可以帮助理解这一点。为什么localtime为不同的时间戳提供相同的输出?

       #include<stdio.h>

       #include<time.h>
       int main() 
       {
       int first = time(NULL);
       printf("%d\n", first);

       int second = first + 6;
        printf("%d\n", second);

       time_t loc_time = first;
       struct tm *starttime = localtime(&loc_time);

       time_t loc_time_end = second;

       struct tm *endtime  = localtime(&loc_time_end);

       printf("=====> start time is %d-%d-%d %02d:%02d:%02d", starttime->tm_mday, 1+starttime->tm_mon, starttime->tm_year+1900, starttime->tm_hour, starttime->tm_min, starttime->tm_sec); 
       printf("=====> end time is %d-%d-%d %02d:%02d:%02d", endtime->tm_mday, 1+endtime->tm_mon, endtime->tm_year+1900, endtime->tm_hour, endtime->tm_min, endtime->tm_sec); 

       }

输出:-1515384712 1515384718 =====&GT;开始时间是8-1-2018 04:11:58 =====&gt;结束时间是8-1-2018 04:11:58

提前致谢。

0 个答案:

没有答案