Skip to content

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

class method

Time.utc

Time.utc(year, month=1, day=1, hour=0, min=0, sec_i=0, usec=0) → new_time
Time.utc(sec_i, min, hour, day, month, year, dummy, dummy, dummy, dummy) → new_time

Returns a new Time object based the on given arguments; its timezone is UTC.

In the first form (up to seven arguments), argument year is required.

Example
Time.utc(2000)                  # => 2000-01-01 00:00:00 UTC
Time.utc(0, 1, 2, 3, 4, 5, 6.5) # => 0000-01-02 03:04:05.0000065 UTC

In the second form, all ten arguments are required, though the last four are ignored. This form is useful for creating a time from a 10-element array such as is returned by to_a.

Example
array = Time.now.to_a
p array # => [57, 26, 13, 24, 4, 2021, 6, 114, true, "Central Daylight Time"]
array[5] = 2000
Time.utc(*array) # => 2000-04-24 13:26:57 UTC

Parameters:

  • year: an integer year.

  • month: a month value, which may be:

    • An integer month in the range 1..12.

    • A 3-character string that matches regular expression /jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec/i.

  • day: an integer day in the range 1..31 (less than 31 for some months).

  • hour: an integer hour in the range 0..23.

  • min: an integer minute in the range 0..59.

  • isec_i is the integer number of seconds in the range 0..60.

  • usec is the number of microseconds (Integer, Float, or Rational) in the range 0..1000000.

Alias: Time.gm.

Related: Time.local.

See also #utc #utc? .strptime .xmlschema also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0