为什么计算机时间的标准是 GMT 而不是 UTC?

发布于 2024-12-27 17:16:03 字数 267 浏览 0 评论 0原文

对我来说,就像我在编程中看到的与时间相关的算法一样,GMT 是基准时间。例如,我被告知始终将 GMT+00 的时间存储在数据库中,这样时区更改就不会破坏任何内容。

  1. GMT 似乎是软件开发的基准时区,我对吗?

  2. 如果是这样,为什么不是 UTC?考虑到即使 Unix 时间戳也是从 UTC 定义的 (http://en.wikipedia.org/wiki/Unix_time),为什么说“UTC+01”而不是“GMT+01”并不常见

It feels to me like everywhere I've seen time related algorithms in programming, GMT was the base time. For example, I was told to always store time in a DB in GMT+00 so that time zone changes don't disrupt anything.

  1. Am I right that GMT seems to be the base time zone in software development?

  2. If so, why not UTC? Why is it not common to say "UTC+01" instead of "GMT+01" considering that even Unix timestamps are defined from UTC (http://en.wikipedia.org/wiki/Unix_time)

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

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

发布评论

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

评论(5

放低过去 2025-01-03 17:16:03

这个被接受的回应实际上是错误的。首先,它们无论如何都不一样。第二个 UTC 并不更符合基于地球自转的“真实”时间,恰恰相反。 UTC 在“时间”测量方面更加精确。每一秒的持续时间都是一样的,因为它是基于原子时间的,而且精度高得令人难以置信(抵消一秒需要三万年)。

GMT 而是跟踪地球自转,因为地球自转并不总是相同(地球自转正在减慢),每一秒都不同。当然,时间上的差异非常小。但出于科学目的,UTC 比 GMT 更准确。

这就是为什么 UTC 每 4/5 年变化 +2 秒(因为地球自转速度每秒钟变慢,因此自转所需的时间必须大于 UTC),因此它与 GMT 地球自转时间相差不到一秒。

This accepted response is actually wrong. First they are not the same by any means. Second UTC is NOT more closely in line with "true" time based off of earth's rotation, is exactly the opposite. UTC is more precise in terms of 'time' measure. Each second last the same since is based on atomic time and the precision is increidble hight (it would take 30 thousand years to offset one second).

GMT instead tracks earth rotation, since this is not always the same (the earth rotation is slowing down) each second differs. Of course, differs in a really small ammount of time. But for cientific purposes, is a lot more accurate UTC than GMT.

This is the reason why UTC changes +2 seconds every 4/5 years (since earth rotation is slower each second it takes to rotate has to be bigger than UTC), so it follows GMT earth rotation time by less than a second of difference.

只是在用心讲痛 2025-01-03 17:16:03

GMT 和 UTC 时间相同。 UNIX 时间基于 UTC,因此您可能会在 UNIX 和 *nix 系统上找到更多时间。

UTC 作为官方时间也得到了更密切的跟踪(即更接近基于地球自转的“真实”时间)。但除非您的软件需要精确到秒的计算,否则无论您使用 GMT 还是 UTC,都应该没有什么区别。

尽管如此,您可能会考虑向用户显示哪些内容。一种格式可能比另一种更熟悉。对于全球应用程序,我通常选择 UTC,对于欧洲或英国的应用程序,我通常选择 GMT。

GMT and UTC are the same time. UNIX time is based off of UTC, so you might find that more on UNIX and *nix systems.

UTC is also more closely tracked as an official time (i.e. is more closely in line with "true" time based off of earth's rotation). But unless your software needs to-the-second calculations, it shouldn't make a difference whether you use GMT or UTC.

Although, you might consider which to display to users. One format may be more familiar than another. I would typically go with UTC for global applications, and GMT for European or UK-based applications.

海风掠过北极光 2025-01-03 17:16:03

我认为了解 IANA 时区 目前使用缩写“GMT”会很有趣现在和 6 个月后(以赶上目前采用夏令时的时间)。

使用这个免费开源C++11/14库,我编写了这个程序:

#include "tz.h"
#include <string>
#include <iostream>
#include <vector>

template <class Duration>
std::vector<date::zoned_time<std::common_type_t<Duration, std::chrono::seconds>>>
find_by_abbrev(date::sys_time<Duration> tp, const std::string& abbrev)
{
    using namespace std::chrono;
    using namespace date;
    std::vector<zoned_time<std::common_type_t<Duration, seconds>>> results;
    auto& db = get_tzdb();
    for (auto& z : db.zones)
    {
        if (z.get_info(tp).abbrev == abbrev)
            results.push_back(make_zoned(&z, tp));
    }
    return results;
}

int
main()
{
    using namespace std::chrono;
    using namespace date;
    auto now = system_clock::now();
    auto v = find_by_abbrev(now, "GMT");
    for (auto const& x : v)
        std::cout << format("%F %H:%M:%S %Z %z", x) << " "
                  << x.get_time_zone()->name() << '\n';
    std::cout << '\n';
    v = find_by_abbrev(now + months{6}, "GMT");
    for (auto const& x : v)
        std::cout << format("%F %H:%M:%S %Z %z", x) << " "
                  << x.get_time_zone()->name() << '\n';
}

这搜索了这个星球对于当前使用“GMT”的所有时区(现在和 6 个月后),并将其打印出来:

2016-06-18 01:00:25.632773 GMT +0000 Africa/Abidjan
2016-06-18 01:00:25.632773 GMT +0000 Africa/Accra
2016-06-18 01:00:25.632773 GMT +0000 Africa/Bissau
2016-06-18 01:00:25.632773 GMT +0000 Africa/Monrovia
2016-06-18 01:00:25.632773 GMT +0000 America/Danmarkshavn
2016-06-18 01:00:25.632773 GMT +0000 Atlantic/Reykjavik
2016-06-18 01:00:25.632773 GMT +0000 Etc/GMT

2016-12-17 15:55:01.632773 GMT +0000 Africa/Abidjan
2016-12-17 15:55:01.632773 GMT +0000 Africa/Accra
2016-12-17 15:55:01.632773 GMT +0000 Africa/Bissau
2016-12-17 15:55:01.632773 GMT +0000 Africa/Monrovia
2016-12-17 15:55:01.632773 GMT +0000 America/Danmarkshavn
2016-12-17 15:55:01.632773 GMT +0000 Atlantic/Reykjavik
2016-12-17 15:55:01.632773 GMT +0000 Etc/GMT
2016-12-17 15:55:01.632773 GMT +0000 Europe/Dublin
2016-12-17 15:55:01.632773 GMT +0000 Europe/London

我很高兴看到在所有情况下 UTC 偏移量都是 +0000。你永远不知道政客和时区的情况。一些立法机构可以轻松宣布“绿山时间”(也许明天就可能)。

I thought it would be fun to discover what IANA timezones are currently using the abbreviation "GMT", both now and 6 months from now (to catch those currently on daylight saving time).

Using this free, open source C++11/14 library, I wrote this program:

#include "tz.h"
#include <string>
#include <iostream>
#include <vector>

template <class Duration>
std::vector<date::zoned_time<std::common_type_t<Duration, std::chrono::seconds>>>
find_by_abbrev(date::sys_time<Duration> tp, const std::string& abbrev)
{
    using namespace std::chrono;
    using namespace date;
    std::vector<zoned_time<std::common_type_t<Duration, seconds>>> results;
    auto& db = get_tzdb();
    for (auto& z : db.zones)
    {
        if (z.get_info(tp).abbrev == abbrev)
            results.push_back(make_zoned(&z, tp));
    }
    return results;
}

int
main()
{
    using namespace std::chrono;
    using namespace date;
    auto now = system_clock::now();
    auto v = find_by_abbrev(now, "GMT");
    for (auto const& x : v)
        std::cout << format("%F %H:%M:%S %Z %z", x) << " "
                  << x.get_time_zone()->name() << '\n';
    std::cout << '\n';
    v = find_by_abbrev(now + months{6}, "GMT");
    for (auto const& x : v)
        std::cout << format("%F %H:%M:%S %Z %z", x) << " "
                  << x.get_time_zone()->name() << '\n';
}

This searches the planet for all timezones that are currently using "GMT", both now, and 6 months from now, and prints them out:

2016-06-18 01:00:25.632773 GMT +0000 Africa/Abidjan
2016-06-18 01:00:25.632773 GMT +0000 Africa/Accra
2016-06-18 01:00:25.632773 GMT +0000 Africa/Bissau
2016-06-18 01:00:25.632773 GMT +0000 Africa/Monrovia
2016-06-18 01:00:25.632773 GMT +0000 America/Danmarkshavn
2016-06-18 01:00:25.632773 GMT +0000 Atlantic/Reykjavik
2016-06-18 01:00:25.632773 GMT +0000 Etc/GMT

2016-12-17 15:55:01.632773 GMT +0000 Africa/Abidjan
2016-12-17 15:55:01.632773 GMT +0000 Africa/Accra
2016-12-17 15:55:01.632773 GMT +0000 Africa/Bissau
2016-12-17 15:55:01.632773 GMT +0000 Africa/Monrovia
2016-12-17 15:55:01.632773 GMT +0000 America/Danmarkshavn
2016-12-17 15:55:01.632773 GMT +0000 Atlantic/Reykjavik
2016-12-17 15:55:01.632773 GMT +0000 Etc/GMT
2016-12-17 15:55:01.632773 GMT +0000 Europe/Dublin
2016-12-17 15:55:01.632773 GMT +0000 Europe/London

I was gratified to see that in all cases the UTC offset was +0000. You never know with politicians and timezones. Some legislative body could easily proclaim "Green Mountain Time" (and just might tomorrow).

南城旧梦 2025-01-03 17:16:03

GMT 和 UTC 不是一回事。阅读 https://en.wikipedia.org/wiki/Greenwich_Mean_Time 以及其中的链接UTC 为区别。

一些计算机用户感到困惑的是,在 Windows 7 之前,没有任何 Microsoft 操作系统完全支持 UTC,因此一直将国际时间参考标记为 GMT。

关键问题是Windows如何读取和设置BIOS时钟。 Windows XP 无法将 BIOS 时钟设置为 UTC,因此您必须将 BIOX 时钟设置为本地时间,然后依靠 Windows 来跟踪差异。

从 Windows 7 开始,Windows 可以将 BIOS 时钟设置为 UTC,并且所有计算(大部分?)都与 UTC 一致,因此 Microsoft 决定将标签从 GMT 切换为 UTC。

请参阅:

https://superuser.com/questions/185773/does- windows-7-support-utc-as-bios-time

GMT and UTC are not the same thing. Read https://en.wikipedia.org/wiki/Greenwich_Mean_Time and the link in there to UTC for the distinctions.

Some computer users are confused by the fact that until Windows 7, no Microsoft operating system fully supported UTC, and thus kept labeling the international time reference as GMT.

The key issue is how Windows reads and sets the BIOS clock. Windows XP can't handle setting the BIOS clock to UTC, so you must set the BIOX clock to local time, and then rely on Windows keeping track of the difference.

As of Windows 7, Windows can handle setting the BIOS clock to UTC and does all of the calculations (mostly?) consistent with UTC, so Microsoft decided to switch the label from GMT to UTC.

See:

https://superuser.com/questions/185773/does-windows-7-support-utc-as-bios-time

南城旧梦 2025-01-03 17:16:03

我想说这是因为大多数人都习惯了 GMT。如果您要向某人显示信息,特别是时间,您会需要一种他们可以轻松理解的格式。使用 GMT 可以节省与 UTC 相互转换的额外步骤。

I would say that it is because most people are used to GMT. If you're going to display information to a person, specifically time, you would want a format they can easily understand. Using GMT saves you the extra steps of converting to UTC and back.

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