How do I change the zone offset for a time in Ruby on Rails?

前端 未结 13 2401
感情败类
感情败类 2020-12-30 22:03

I have a variable foo that contains a time, lets say 4pm today, but the zone offset is wrong, i.e. it is in the wrong time zone. How do I change the time zone?

When

13条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-30 22:27

    Here is what worked for me...

    def convert_zones(to_zone)
       to_zone_time = to_zone.localtime
    end
    
    
    # have your time set as time
    
    time = convert_zones(time)
    time.strftime("%b #{day}, %Y (%a) #{hour}:%M %p %Z")
    

提交回复
热议问题