End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
Time.local
static VALUE
time_s_mktime(int argc, VALUE *argv, VALUE klass)
{
struct vtm vtm;
time_arg(argc, argv, &vtm);
return time_localtime(time_new_timew(klass, timelocalw(&vtm)));
}
Returns a new Time object based the on given arguments; its timezone is the local timezone.
In the first form (up to seven arguments), argument year is required.
Time.local(2000) # => 2000-01-01 00:00:00 -0600 Time.local(0, 1, 2, 3, 4, 5, 6.5) # => 0000-01-02 03:04:05.0000065 -0600
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 those 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.local(*array) # => 2000-04-24 13:26:57 -0500
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.mktime.
Related: Time.utc.