Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Ask HN: Why is a Unix timestamp not a “valid date string” in the spec?
3 points by kaishiro on April 20, 2021 | hide | past | favorite | 3 comments
While implementing an HTML <time> element recently I found it strange that it did not accept a Unix timestamp as valid input for it's contents or it's datetime attribute.

Taking a look at the spec [1], the W3C states that the input must be a "valid date string with optional time". This, in turn, links through to the microsyntax spec [2], which gives a number of acceptable input patterns - none of which are a Unix timestamp.

I find this to be a curious design decision as the purpose for the time element itself, as stated by the W3C, is "...a way to encode modern dates and times in a machine-readable way..." - and what would be more machine-readable than a Unix timestamp?

Is it simply because a Unix timestamp is - on it's face - a number and not a string? Just wondering if anyone here had any additional insight.

[1] https://www.w3.org/TR/2011/WD-html5-author-20110809/the-time-element.html

[2] https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-date-string-with-optional-time



My guess is it’s because Unix timestamps aren’t calendar date and times. The same number could mean a different date and time depending on which timezone is used.

Given a Unix timestamp, there’s no way to know which date/time the author intended. The browser can only map a Unix timestamp into the user’s timezone, but it wouldn’t know which timezone the document/page refers to.


I don't think this is true, because epoch time does not have a timezone, because 0 already corresponds to a certain timezone. Although epoch time isn't exactly "just UTC", as explained in the very interesting StackOverflow question below, it is close enough, and it does not change with the timezone.

https://stackoverflow.com/questions/23062515/do-unix-timesta...


A timezone can’t be encoded with a Unix time stamp, or a date without a time, or just a time. Unix timestamps ignore leap seconds and treat days as 86400 seconds, so it doesn’t correspond directly to UTC. And they aren’t readable by humans. There are many reasons Unix timestamps aren’t appropriate for encoding a date and time.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: