c++ - std::localtime 一秒导致 30 分钟的差距

标签 c++ localtime

#include <iostream>
int main(){
    std::time_t t = 893665799;
    std::tm * tm = std::localtime(&t);
    printf("local time duration =>year:%d, month:%d, day:%d, hour:%d, min:%d, sec:%d\n",tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);

    t = 893665800;
    tm = std::localtime(&t);
    printf("local time duration =>year:%d, month:%d, day:%d, hour:%d, min:%d, sec:%d\n",tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
}

893665799 是一个神奇的 utc。

当您将时区更改为皮特凯恩群岛时。

日志显示如下

本地时间 =>年:98,月:3,日:26,时:23,分:59,秒:59

本地时间 =>年:98,月:3,日:27,时:0,分:30,秒:0

这是怎么回事?为什么 1 秒会导致 30 分钟的差距??

最佳答案

鉴于给定的 time_t 恰好是进入新小时之前的一秒,这几乎可以肯定与夏令时或其他一些调整有关。

而且,用一点 Google-fu,here它是:

27 Apr 1998 - Time Zone Change (PNT → PST)

When local standard time was about to reach Monday, 27 April 1998, 12:00:00, midnight clocks were turned forward 0:30 hours to Monday, 27 April 1998, 12:30:00 am local standard time instead.

这实际上经常发生,世界上许多国家都在随意改变他们的本地时间:-)

关于c++ - std::localtime 一秒导致 30 分钟的差距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44193213/

相关文章:

C++ gtk打开多个窗口

c++ - 多维 std::array

unix -/usr/share/zoneinfo 史诗失败

sqlite - SQLite 中的 UTC 时间错误

c - localtime(_r) 反转行为

c++ - 使用 ctime 将给定日期提前到下一个日历日期的问题

c++ - Python GIL 和线程

c++ - 除了LAME MP3之外,还有哪些开源的C/C++音频压缩选项?

c - localtime_s取决于智利圣地亚哥时区的当前系统时间

c++ - 在 HPUX 上以编程方式获取应用程序的 CPU 和内存使用情况