Shared publicly  - 
 
RESTful timestamp format: Which would you use?

What timestamp format do you think is best to output from a RESTful API?

milliseconds since 1970 is extremely simple and can be easily converted into any format. Plus, you can compare to current time or another value without even converting at all.

human-readable formats like ISO 8601 (2011-07-14T19:43:37+0100) are much more popular for some reason. It's nice they're human-readable to be sure, but I feel like they always cause a lot of unnecessary parsing hassle.
1
Stuart Memo's profile photoGary Royal's profile photoSparky Rhode's profile photoMichael Mahemoff's profile photo
11 comments
 
2nd one. Although I do like the idea that something magical happened in 1970 that we have to base all of time on it.
 
Yeah, never really been a fan of rugby ;)
 
In JSON and query parameters I would use milliseconds. In XML and HTML I would prefer ISO.
 
I would use a timestamp if I anticipated doing date arithmetic on the client side (i.e. adjusting for the user's timezone or formatting the date  and time for the user's locale) but a time string in cases where the date is historic or immutable (news, past events, etc).
 
@JohnAdriaans pointed out the browser incompatibilities with ISO formats. That's a key factor I hadn't considered and pushes the argument over the edge...millis it is!
 
+Michael Mahemoff It's not extra parsing hassle when you have a library that does it for you.  Human-readable wire formats are nice and easy to debug.  Also, in a heterogeneous networking world, using a timestamp that is in no system's native format probably avoids a lot of lazy-programmer errors.
 
+Sparky Rhode My guess is that a JSON API is exponentially less likely to be used by developers if they have to find a library to do it, especially if you're competing with similar APIs. It reduces the chance they'll bother to try it and increases the chance they'll get errors on the way. I just find in practice that it's usually a lot of hassle working out what exact date format I'm seeing and then trying to work out which library to use. Whereas every date/time library has an easy way to convert from millis to the standard timestamp type.

I agree on human-readable, that's a big part of REST and a big help for debugging. That's really the main thing ISO formats have going for them.

+Manas Tungare Hadn't thought about that, that is a nice benefit for some situations and especially if you think across an entire suite of services. In my case, it's always going to be millis, so it doesn't really make much odds.
Add a comment...