C 中的时间函数据说返回 Linux 系统上自纪元以来的秒数。当我打印出秒数时,我得到了 139880488649 秒,但数学并没有加起来。我错过了什么?
139880488649 秒/3600 秒/24 小时/365 天 = 4435.581 年。
我差了 1000 倍。时间不是以秒为单位返回的吗?
time_t curTime;
time(&curTime);
printf("sec = %d", curTime);
最佳答案
您显示的值 (1,389,880,488,649) 相差 1000 倍。看起来,您得到的时间以毫秒为单位。
在 *nix 和 Linux 上,time
始终在 秒 内返回值。
更新:
Linux 和 POSIX 将 time()
的返回值指定为自纪元以来的秒数,另请参见 time
. ISO C , 然而,对返回类型含糊不清,只谈论
implementation’s best approximation to the current calendar time.
关于c - 为什么 c 中的时间函数返回毫秒而不是秒?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23376325/