开发者

How do I convert this timestamp into a MySQL DATETIME object in Ruby?

开发者 https://www.devze.com 2023-03-28 13:23 出处:网络
I\'m fetching GPS data to display on a Google map in a Rails 2.3.8 app. The timestamp for each data point is 开发者_如何学Pythonin this format:

I'm fetching GPS data to display on a Google map in a Rails 2.3.8 app.

The timestamp for each data point is 开发者_如何学Pythonin this format:

2011-08-14T09:23:11.000Z

I need to get that into MySQL as a DATETIME object so I can then sort and filter the track points by time.

Any suggestions?


ActiveRecord usually will convert this for you when you save your object into the database. If for some reason, you're bypassing AR, you can convert it to db format via:

"2011-08-14T09:23:11.000Z".to_s(:db)


 Time.parse "2011-08-14T09:23:11.000Z"
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号