Ruby time interval offset problem

I need to set the time zone offset to Time in order to get the current day of the week for the specified offset. This is not with rails, so for this I need a clean Ruby formatter / parser.

Thanks.

+4
source share
3 answers

Here is what I found:

require 'date' local = DateTime.now new_offset = Rational(0, 24) #put the offset you want as first argument utc = local.new_offset(new_offset) 
+3
source

Returns the offset in seconds between the time zone of time and UTC.

  t = Time.gm(2000,1,1,20,15,1) #=> 2000-01-01 20:15:01 UTC t.gmt_offset #=> 0 l = t.getlocal #=> 2000-01-01 14:15:01 -0600 l.gmt_offset #=> -21600 
0
source
 #As a string t = Time.new(2011,6,27,14,10,0, "+07:00") # or in seconds from UTC t = Time.new(2011,6,27,14,10,0, 7*60*60) 
0
source

All Articles