如果计算机更改地理位置,系统时钟仍会准确返回UTC吗?

发布于 2025-02-13 19:31:45 字数 336 浏览 0 评论 0原文

假设某人从一个拥有UTC的国家/地区到+/- x HR时区。在此旅程中,他们的设备(例如计算机或移动设备)被完全关闭。

到达目的地后,一旦设备在没有互联网的情况下打开后, System_Clock :: Now()是否会返回UTC时间的正确值?

相关 )没有互联网连接的工作?

Suppose someone travels from a country with UTC to +/- X hr timezone. Their device such as a computer or a mobile, is completely switched off during this journey.

Upon reaching the destination, once the device is switched ON without internet,
Will the system_clock::now() return a correct value of the UTC time?

Related: How datetime.datetime.now() works without internet connection?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

黎歌 2025-02-20 19:31:45

是的,只要您不更改任何设置。

如果您不让计算机的位置更改计算机的位置,则它将继续运行,就好像在以前的位置一样。当地时间将是错误的,但是UTC将根据先前的设置正确计算。

Yes, as long as you don't change any settings.

If you change your computer's location without letting it be aware, it will continue to function as though it was in the previous location. The local time will be wrong, but the UTC will correctly calculate based on the previous settings.

ま柒月 2025-02-20 19:31:45

这可能是一个操作系统问题,但通常我希望系统时钟被普遍设置为UTC,并且TZ偏移量将单独存储并应用于更高级别的时间函数,例如std :: Time()例如。

如果您特别想要UTC,则可能std :: gmtime()更合适,因为它被明确记录为UTC,而不论本地时间或系统时钟。

此外,无论如何,您必须考虑该计算机将如何获得本地时区 - 它需要信息来确定这一点。如果它具有GNSS位置,则可以手动输入或由GNSS位置确定,或者可能会从IP地址“猜测”(在具有多个时区域的领土上很容易是错误的)。无论哪种方式,它都不是魔术。

无论如何,您都可以通过临时手动修改系统的TZ来轻松测试System_Clock的行为。

That is possibly an operating system issue, but normally I would expect the system clock to be universally set to UTC and the TZ offset to be stored separately and applied to higher level time functions such as std::time() for example.

If you specifically want UTC, perhaps std::gmtime() would be more appropriate, since it is explicitly documented as UTC regardless of local time or system clock.

Additionally, regardless of all that, you have to consider how this computer will acquire a local timezone - it needs information to determine that. It might be manually entered, or determined by GNSS position if it has one, or it might "guess" from IP address (which can easily be wrong in territories with multiple timezones). Either way it is not magic.

You can in any event easily test the behaviour of system_clock by temporarily manually modifying your system's TZ.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文