[英]Why does tm_sec range from 0-60 instead of 0-59 in time.h?
My time.h
has the following definition of tm
: 我的time.h
有以下tm
定义:
struct tm {
int tm_sec; /* seconds after the minute [0-60] */
int tm_min; /* minutes after the hour [0-59] */
int tm_hour; /* hours since midnight [0-23] */
...
}
I just noticed that they document tm_sec
as ranging between 0-60 inclusive. 我只是注意到他们将tm_sec
记录在0-60之间。 I've always assumed it ranged from 0-59 just like tm_min
. 我一直认为它的范围是0-59,就像tm_min
一样。 I've certainly never seen a clock read 10:37:60... 我当然没见过时钟阅读时间10:37:60 ......
Do you think this is just a documentation bug left over from this 90's era Berkley-originated file? 你认为这只是这个90年代伯克利起源文件留下的文档错误吗?
Or is there something more subtle going on that I'm unaware of? 或者是否有一些我不知道的更微妙的事情?
Leap seconds are the reason for this: 闰秒是这样的原因:
A leap second is a plus or minus one-second adjustment to the Coordinated Universal Time (UTC) time scale that keeps it close to mean solar time. 闰秒是对协调世界时(UTC)时间刻度的正负1秒调整,使其接近平均太阳时。
When a positive leap second is added at 23:59:60 UTC, it delays the start of the following UTC day (at 00:00:00 UTC) by one second, effectively slowing the UTC clock. 当在UTC时间23:59:60添加正闰秒时,它将后续UTC日(在00:00:00 UTC)的开始延迟一秒,从而有效地减慢了UTC时钟。
The man page for ctime
explains that this is about leap seconds: ctime
的手册页解释说这是关于闰秒:
tm_sec
: The number of seconds after the minute, normally in the range 0 to 59, but can be up to 60 to allow for leap seconds.tm_sec
:分钟后的秒数,通常在0到59的范围内,但最多可以为60,以允许闰秒。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.