End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
Time.utc
static VALUE
time_s_mkutc(int argc, VALUE *argv, VALUE klass)
{
struct vtm vtm;
time_arg(argc, argv, &vtm);
return time_gmtime(time_new_timew(klass, timegmw(&vtm)));
}
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.
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.
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 range1..31(less than 31 for some months). -
hour: an integer hour in the range0..23. -
min: an integer minute in the range0..59. -
isec_iis the integer number of seconds in the range0..60. -
usecis the number of microseconds (Integer,Float, orRational) in the range0..1000000.
Alias: Time.gm.
Related: Time.local.