Converting Time in UTC to Pacific time

后端 未结 3 1087
闹比i
闹比i 2021-02-07 11:17

I get a string from a external method with a time and date like so \"07/09/10 14:50\" is there any way I can convert that time in ruby to \'Pacific US\' time knowin

3条回答
  •  离开以前
    2021-02-07 11:41

    require 'time'

    If you want pacific time just subtract 25200 seconds from Time.new There is a 7 hour difference between pacific time and GMT.

    t = Time.parse((Time.new-25200).to_s)

    Then use strftime to format however you want it to look.

    puts t.strftime("%A %D at %I:%M%p")

提交回复
热议问题