Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

class method

Time.gm

Time.utc(year) → time
Time.utc(year, month) → time
Time.utc(year, month, day) → time
Time.utc(year, month, day, hour) → time
Time.utc(year, month, day, hour, min) → time
Time.utc(year, month, day, hour, min, sec_with_frac) → time
Time.utc(year, month, day, hour, min, sec, usec_with_frac) → time
Time.utc(sec, min, hour, day, month, year, dummy, dummy, dummy, dummy) → time
Time.gm(year) → time
Time.gm(year, month) → time
Time.gm(year, month, day) → time
Time.gm(year, month, day, hour) → time
Time.gm(year, month, day, hour, min) → time
Time.gm(year, month, day, hour, min, sec_with_frac) → time
Time.gm(year, month, day, hour, min, sec, usec_with_frac) → time
Time.gm(sec, min, hour, day, month, year, dummy, dummy, dummy, dummy) → time

Creates a Time object based on given values, interpreted as UTC (GMT). The year must be specified. Other values default to the minimum value for that field (and may be nil or omitted). Months may be specified by numbers from 1 to 12, or by the three-letter English month names. Hours are specified on a 24-hour clock (0..23). Raises an ArgumentError if any values are out of range. Will also accept ten arguments in the order output by Time#to_a.

sec_with_frac and usec_with_frac can have a fractional part.

Example
Time.utc(2000,"jan",1,20,15,1)  #=> 2000-01-01 20:15:01 UTC
Time.gm(2000,"jan",1,20,15,1)   #=> 2000-01-01 20:15:01 UTC
See also #gm .force_zone! .httpdate .at also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2