#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/