joslinm
joslinm

Reputation: 8105

What is the T and Z in timedate getting returned by MongoMapper?

When I return a JSON format of created_at & updated_at from MongoMapper, this is an example of what I see

"updated_at\":\"2012-04-25T16:25:05Z\"

What is the T (time?) and Z at the end?

 irb(main):009:0> Story.last.created_at
  DEBUG - MONGODB (0ms) prototype_development['stories'].find({}).limit(-1)
=> 2012-04-25 16:24:26 UTC
irb(main):010:0> Story.last.created_at.to_s
  DEBUG - MONGODB (0ms) prototype_development['stories'].find({}).limit(-1)
=> "2012-04-25 16:24:26 UTC"
irb(main):011:0> JSON.parse(Story.last.to_json)['created_at']
  DEBUG - MONGODB (0ms) prototype_development['stories'].find({}).limit(-1)
=> "2012-04-25T16:24:26Z"

Upvotes: 1

Views: 599

Answers (1)

shime
shime

Reputation: 9008

This is a standardized time format - ISO8601.

Hit this in irb:

> require 'time' #=> true
> Time.now.utc.iso8601 #=> "2012-05-11T01:28:51Z"

From Wikipedia:

The UTC time zone is sometimes denoted by the letter Z—a reference to the equivalent nautical time zone (GMT), which has been denoted by a Z since about 1950. The letter also refers to the "zone description" of zero hours, which has been used since 1920 (see time zone history). Since the NATO phonetic alphabet and amateur radio word for Z is "Zulu", UTC is sometimes known as Zulu time. This is especially true in aviation, where Zulu is the universal standard. This ensures all pilots regardless of location are using the same 24-hour clock, thus avoiding confusion when flying between time zones.See list of military time zones for letters used in addition to Z in qualifying time zones other than Greenwich.

Upvotes: 8

Related Questions