Skip to content

Instantly share code, notes, and snippets.

@bsimpson
Created November 16, 2012 15:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bsimpson/4088286 to your computer and use it in GitHub Desktop.
Save bsimpson/4088286 to your computer and use it in GitHub Desktop.
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