TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Designing a REST API: Unix Time vs. ISO-8601 (2013)

42 pointsby ducaaleabout 3 years ago

7 comments

koengabout 3 years ago
Unix time is <i>not</i> unambiguous. It is linked to UTC, so occasionally there are leap seconds, and there isn’t a standard format for these (two seconds == one second, or skip a second)[1]. TAI is a better format, but turns out the common TAI libraries just code the TAI offset from Unix time.<p>[1] <a href="https:&#x2F;&#x2F;geometrian.com&#x2F;programming&#x2F;reference&#x2F;timestds&#x2F;index.php" rel="nofollow">https:&#x2F;&#x2F;geometrian.com&#x2F;programming&#x2F;reference&#x2F;timestds&#x2F;index....</a>
评论 #30856272 未加载
评论 #30856625 未加载
评论 #30855416 未加载
评论 #30855448 未加载
评论 #30856358 未加载
评论 #30857699 未加载
deathanatosabout 3 years ago
There&#x27;s also RFC 3339[1] which is, IMO, a bit better. The RFC is readily readable, unlike an ISO standard, and the RFC is — mostly — more restrictive.<p>ISO is fun up until you have to parse &quot;2022-089&quot;. Yes, that&#x27;s a valid ISO date. And it&#x27;s in March. (And yes, I&#x27;ve seen that used in the wild, though I don&#x27;t know why anyone would ever choose that format.)<p>[1]: <a href="https:&#x2F;&#x2F;datatracker.ietf.org&#x2F;doc&#x2F;html&#x2F;rfc3339" rel="nofollow">https:&#x2F;&#x2F;datatracker.ietf.org&#x2F;doc&#x2F;html&#x2F;rfc3339</a>
arjvikabout 3 years ago
Unix Time should be an implementation detail. ISO-8601 is IMO the preferred format for APIs.
stickfigureabout 3 years ago
JSON needs to have a timestamp type. Parsers should automatically convert them to&#x2F;from native language timestamp objects. Human readable is preferred, but really the critical aspect is to make the JSON self-describing. If timestamps are self-describing, any smart editor can display them properly.
评论 #30857091 未加载
评论 #30861484 未加载
评论 #30855286 未加载
评论 #30856480 未加载
divbzeroabout 3 years ago
&gt; <i>A sample of 20 APIs yielded nearly a 50&#x2F;50 split.</i><p>Is it still a 50&#x2F;50 split today? I suspect ISO 8601 has grown to become the standard.
评论 #30856637 未加载
评论 #30856343 未加载
softwarebewareabout 3 years ago
I’m quite surprised that Unix time is so common. My anecdotal experience with dozens of public and internal APIs over 20 years of development is that the most common format is local time followed by ISO. I actually have almost never seen Unix time.
评论 #30856655 未加载
评论 #30855270 未加载
csoursabout 3 years ago
&gt; &quot;Unix time is completely unambiguous.&quot;<p>Looks like someone hasn&#x27;t had to deal with data from multiple different time zones processed by code written by different developers over several years!<p>Unix time could be unambiguous, but it is not in practice. If it has been unambiguous for you, congratulations!<p>Use ISO style dates if you don&#x27;t want to spend the rest of your life explaining what a date actually means.
评论 #30858653 未加载