Convert DateTime String to UTC in rails

后端 未结 3 1371
逝去的感伤
逝去的感伤 2021-01-31 15:29

I have a string like this:

\"2010-01-01 12:30:00\"

I need that to convert to UTC from the current local time zone.

I tried this, but it

3条回答
  •  [愿得一人]
    2021-01-31 16:08

    In Rails 4 and above you can directly use in_time_zone

    "2010-01-01 12:30:00".in_time_zone
    #=> Fri, 01 Jan 2010 12:30:00 EST -05:00
    
    "2010-01-01 12:30:00".in_time_zone.utc
    #=> 2010-01-01 17:30:00 UTC
    

提交回复
热议问题