Rails: How to parse date-time string into a specific time zone

前端 未结 7 1234
天命终不由人
天命终不由人 2020-12-01 10:23

I\'m using Rails 3.2 and ruby 1.9.3 on Debian. I have an app that collects a date, time, and timezone in the form of strings via an HTML form. Something like this:



        
7条回答
  •  误落风尘
    2020-12-01 11:06

    To have DateTime take the date string and attach a timezone other than UTC without changing the values of the date string , use this, its easy , doesnt break on leap day :)

    xx = DateTime.strptime("9/1/15 #{object.time_zone}", "%m/%d/%Y %Z")
    

提交回复
热议问题