Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RESTful API design - best practices for passing dates

Tags:

rest

datetime

api

What is the best practice for sharing dates in an API?

Is it best to share dates with an SQL-like datetime format - 'YYY-MM-DD HH:MM:SS' with an optional timezone embedded inside of it?

Or is it best to use milliseconds based on UTC?

like image 638
Greg Avatar asked Nov 28 '11 17:11

Greg


1 Answers

I prefer to encode times as full ISO 8601 dates, but with the constraint that my code only ever generates them in the UTC timezone. If you've got a good date parsing library (e.g., Jodatime for Java) accepting full ISO 8601 is not particularly difficult and they're at least somewhat readable. (Offsets from some epochal instant are nothing like as easy for people to read.)

like image 99
Donal Fellows Avatar answered Sep 21 '22 14:09

Donal Fellows