本文共 4516 字,大约阅读时间需要 15 分钟。
Some notes about time:
59.0059.2559.5059.7559.00 ← replay59.2559.5059.7500.00 ← increment00.25This is a trade-off: you can't represent a leap second, and your time is guaranteed to go backwards. On the other hand, every day has exactly 86,400 seconds, and you don't need a table of all previous and future leap seconds in order to format Unix time as human-preferred hours-minutes-seconds.
ntpd
can be configured with the directive to announce an upcoming leap second. Most leaf installations don't bother with this, and rely on enough of their upstreams getting it right.Some time-related considerations when programming:
libc
and/or your language's runtime has code to do timezone conversions and formatting. This stuff is tricky, avoid re-implementing it yourself.clock_gettime()
manpage.ntpd
can change the system time in two ways: Special mentions:
DATETIME
type as a binary encoding of its"YYYY-MM-DD HH:MM:SS"
string. It does not store an offset, and interprets times according to @@session.time_zone
: mysql> insert into times values(now());mysql> select unix_timestamp(t) from times;1310128044mysql> SET SESSION time_zone='+0:00';mysql> select unix_timestamp(t) from times;1310164044
There's also a TIMESTAMP
type, which is stored as UNIX time, but has other magic.
In conclusion, if you care at all about storing timestamps in MySQL, store them as integers and use the UNIX_TIMESTAMP()
and FROM_UNIXTIME()
functions.
转载地址:http://qpiqb.baihongyu.com/