c++ - time() 返回的 time_t 是否特定于区域?

标签 c++ c time timezone

我刚接触 <time.h>并对 time_t 有疑问和 time() .

我阅读了如下记录的函数 time():

time_t time ( time_t * timer ); Get current time

Get the current calendar time as a time_t object.

The function returns this value, and if the argument is not a null pointer, the value is also set to the object pointed by timer.

文档没有讨论时区。

因此,对于以下 C++ 代码:

time_t t = time(NULL);

如果两台机器,一台在美国,一台在英国,都执行函数调用time(NULL)同时,返回的 time_t 对象是否相同?

无论时区如何,time() 都会返回一个值吗?

最佳答案

不,它不是特定于区域的。它返回一个值,该值是自 1970 年 1 月 1 日以来以 UTC 计算的秒数,忽略闰秒。因此(原则上)如果两台机器同时执行调用,返回的值将是相同的,即使它们在两个不同的时区工作。

关于c++ - time() 返回的 time_t 是否特定于区域?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7426575/

相关文章:

c - 返回函数不起作用。使用毕达哥拉斯定理

创建一个设置了 N 个最低有效位的掩码

c - *** 错误 `./prog5' : double free or corruption (out): 0x0000000001cc3260 *** Aborted (core dumped)

jquery - 每 3 秒执行一次操作,而不是单击按钮操作

c++ - 修改二进制文件

c++ - SleepEx 是否保证在超时之前调用所有挂起的完成回调?

Python:时间日期问题

php - 翻译月份名称的最佳方法

c++ - 为什么一个方法会对同一个变量有 const 和非 const 参数?

c++ - OpenGL - GLM 和 GLSL,它们有何不同?