Frage

I my web REST API service I've decided to return a dateTime data as a string with a timezone which looks like this: "someDate":"2012-01-23T22:52:37.039+02:00" I wonder, how idiomatic is it? If I returned it as Unix time stamp, would it be more sensible?

War es hilfreich?

Lösung

Personally, I prefer using unix timestamps in situations like this because it is completely timezone agnostic and leaves the timezone interpretation entirely up to the client. Additionally, depending on your client, it's generally less code to parse a unix timestamp into a date than a date string, but that's likely only an ancillary consideration.

Andere Tipps

Personally I prefer using the “Epoch time”. It’s not very readable, but it’s very well defined and much shorter then other formats.

References:

The format is described in RFC 3339: Date and Time on the Internet: Timestamps -- a profile of ISO 8601.

It is unambiguous and both human and machine readable.

POSIX timestamp is less readable e.g., 1327351957.039 and there is no indication of a local time.

If parsing datetime strings is a performance bottleneck in your application then you could cache the timestamp value.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top