3 ms·
(1) dates/times before 1970 cannot be represented using a Unix timestamp (2) you'll have much fun with leap seconds (3) a Unix timestamp is just a number repr
by bad_user 14y ago
(1) dates/times before 1970 cannot be represented using a Unix timestamp
(2) you'll have much fun with leap seconds
(3) a Unix timestamp is just a number represented as floating point ... not much different from all other numbers. A standard date representation on the other hand has a unique format that's distinguishable from all other data types. This comes in handy not only for humans reading it, but also for parsers of weak formats such as CSV
Also data lives longer than both code or the documentation describing the data, this being the main argument for text-based protocols.
(4) programmers are people with feelings too and would rather read human readable dates (since they are so common), rather than lookup the boilerplate for converting a Unix timestamp to a human readable format. Here's the Python version, which I know by heart just because I had to deal with a lot of timestamps:
timestamp = time.time() # now
datetime(*time.gmtime(timestamp)[:6]).strftime("%c")
Oh wait, that gives me the date in UTC. Ok, that date is meant for me, the programmer that knows what he's doing, so here's how I can read it:
datetime(*time.localtime(timestamp)[:6]).strftime("%c")
Great, now I should write a blog post about it. Or you know, just use standard date formats that are human readable, because there's a reason why our forefathers used the dates representations that we use today, instead of counting scratches on wood or something ;-)
- ZenPsycho 14y agoTimes before 1970 can be stored as negative numbers.
- bad_user 14y agoTrue, but many libraries still do not know how to deal with negative timestamps. For instance PHP on Windows, prior to 5.1.0. MySQL's FROM_UNIXTIME was also not working last time I tried it. And many applications and scripts can break, like those that store and manipulate timestamps assuming a certain format (e.g. positive integers). The Unix timestamp was created to deal with timestamps, not with date representations. Therefore this requirement (dates prior to 1970) was not an issue that had to be dealt with explicitly.
- ZenPsycho 14y agocalling out PHP is a bit of a cheap shot. Nothing works properly in PHP.