小编Inj*_*tea的帖子

C中的时间函数始终显示"Wed Dec 31 23:59:59 1969"

我需要为我的应用程序记录当前日期和时间.我用C编写了代码.我附上了代码

#include <stdio.h>
#include <time.h>

int main()
{   time_t t;


     while(1)
     { time(&t);
       printf("Today's date and time : %s",ctime(&t));   
     } 

}
Run Code Online (Sandbox Code Playgroud)

输出是

Today's date and time : Wed Dec 31 23:59:59 1969
Today's date and time : Wed Dec 31 23:59:59 1969
Today's date and time : Wed Dec 31 23:59:59 1969
Today's date and time : Wed Dec 31 23:59:59 1969
Run Code Online (Sandbox Code Playgroud)

自UNIX时间开始以来,时间没有得到更新.我在另一台计算机上运行相同的程序,运行得很好.为什么我的计算机出现此错误?如何解决?

谢谢

任何帮助赞赏.

编辑:代码中有一个错误,我纠正了它,以便在while循环中更新时间

c time unix-timestamp

4
推荐指数
1
解决办法
551
查看次数

标签 统计

c ×1

time ×1

unix-timestamp ×1