views:

458

answers:

2

JSON text (RFC 4627) has unambigious representation of objects, arrays, strings, numbers, Boolean values (literally true or false) and null. However, it has nothing defined for representing time information like date and time of day, which is very common in applications. What are the current methods in use to represent time in JSON given the constraints and grammar laid out in RFC 4627?

Note to respondents: The purpose of this question is to document the various methods known to be in circulation along with examples and relative pros and cons (ideally from field experience).

A: 

There is no set literal so use what's easiest for you. For most people, that's either a string of the UTC output or an long-integer of the UTC-centered timecode.

Read this for a bit more background: http://msdn.microsoft.com/en-us/library/bb299886.aspx

Oli
+4  A: 

The only representation that I have seen in use (though, admittedly, my experience is limited to DOJO) is ISO 8601, which works nicely, and represents just about anything you could possibly think of.

For examples, you can visit the link above.

Pros:

  • Represents pretty much anything you could possibly throw at it, including timespans. (ie. 3 days, 2 hour)

Cons:

  • Umm... I don't know actually. Other than perhaps it might take a bit of getting used to? It's certainly easy enough to parse, if there aren't built in functions to parse it already.
Matthew Scharley