我刚接触 <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/