Date from MongoDB prints as "date":"2011-05-12T13:51:33Z"
Why am I getting the "T" and "Z" in the date when I fetch it from MongoDB and convert it to JSON using Rails3?
"date":"2011-05-12T13开发者_StackOverflow中文版:51:33Z"
Thanks
Fetch:
@bs = coll.find("headers.from" => email, "date" => {"$gte" => initial_date, "$lte" => Time.now.utc})
Insert:
date : { type: Date, default: Date.now }
It's an ISO8601 formatted datetime. The 'T' separates the date from the time and the 'Z' indicates that the date is UTC (GMT). MongoDB doesn't support a Date (only) type, instead everything is converted to a timestamp.
You can drop into the mongo console and run a query you'll see date (and time) fields are stored as ISODate("2011-05-12T13:51:33Z").
精彩评论