Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Rails and Javascript UTC timestamps

#Rails:#

ActiveSupport.use_standard_json_time_format #=> true

http://apidock.com/rails/DateTime/to_json "Returns a JSON string representing the datetime. If ActiveSupport.use_standard_json_time_format is set to true, the ISO 8601 format is used."

http://en.wikipedia.org/wiki/ISO_8601 "If the time is in UTC, add a Z directly after the time without a space. Z is the zone designator for the zero UTC offset. "09:30 UTC" is therefore represented as "09:30Z" or "0930Z". "14:45:15 UTC" would be "14:45:15Z" or "144515Z"."

#Javascript:#

Date.parse(""2012-11-16T14:46:04Z") # => 1353077164

Unixtimestamp.com shows 11 / 16 / 12 @ 8:46:04am EST (+DST when appropriate)

new Date().getTime() # => 1353079050

Unixtimestamp.com shows 11 / 16 / 12 @ 9:17:30am EST (+DST when appropriate)

This should demonstrate that parsing a Rails ISO 8601 formatted date yields a UTC time. Also, calling new Date().getTime() is yielding seconds since epoch in UTC time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.