c - 为什么 c 中的时间函数返回毫秒而不是秒?

标签 c linux

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/

相关文章:

c++ - 在 C 和 C++ 中使用以前未知的参数回调函数

c - 简单代码的gcc编译错误

c - 使用超出预期内存使用量的大型 mmap 调用是否会产生性能成本?

python - 使用 python 编译 caffe 的问题,对 `std::__cxx11::....' 的 undefined reference

c - 搜索大字符数组时降低 CPU 使用率

c - 初始化结构体中的数组

c - doxygen:C 中声明与定义的 html 格式

linux - 无法打开共享对象文件 : no such file or directory [FSL installation on VM]

linux - 将 3000k 个 txt 文件合并成一个 txt 文件 Linux

linux - 在 Docker 中安装 Rust 工具链时,Bash `source` 命令不起作用