The Time
class represents the time value and its
operations. Time.now
returns the current time object.
The timestamps of the files returned by
File#stat
are instances of
this class.
Object
Comparable
now
now
Returns the current time object.
at(time)
Creates the time object at time. The argument
time must be either the instance of the Time
class or the number, which is considered as seconds since
00:00:00 GMT, January 1, 1970.
gm(year, month, day, hour, min, sec)
Returns the Time
object specified by the arguments in GMT.
The arguments after the second one can be omitted. The default value
for the omitted argument is the lowest value for that argument.
If the month
argument is a fixnum, it must be from
1(January) to 12(December). If it is string, it must be the English
month name or the number starting from 1(January) to 12(December).
If the number of arguments are equals to that of elements of
Time#to_a, Time.gm
understands them
properly, even if they are in the little endian (seconds comes first)
format.
local(year, month, day, hour, min, sec)
mktime(year, month, day, hour, min, sec)
Returns the Time
object specified by the arguments in localtime.
The arguments after the second one can be omitted. The default value
for the omitted argument is the lowest value for that argument.
times
Returns the user and system CPU times structure, which attributes are:
Times are floating-point numbers and are measured in seconds. (See times(3))utime # user time stime # system time cutime # user time of children cstime # system time of children
self + other
Returns the time object which is later than self
by
other.
self - other
Returns the diff of the time in float, if the other if the
time object. If the other is the numeric value, it returns
the time object earlier than self
than other.
self <=> other
Comparison of the times. other must be a time object or an integer or a floating-point number. Numbers are considered as seconds since 00:00:00 GMT, January 1, 1970.
asctime
ctime
to_s
Converts the time into the string form like ctime(3).
gmtime
Sets timezone of the time object to GMT. The time object operates time in GMT thereafter. To print time in GMT:
print Time.now.gmtime, "\n"
gmtime
returns self
.
localtime
Sets timezone of the time object to localtime, which is default. Returns time object itself.
to_i
tv_sec
Returns the time since the epoch, 00:00:00 GMT, January 1, 1970, measured in seconds.
sec
min
hour
mday
day
mon
month
year
wday
yday
zone
isdst
Returns the internal values of the time object. All methods return an
integer value, except zone
, which returns the timezone name
string. (c.f. localtime(3))
Notice: Unlike tm struct, month returns 1 for January, year returns 1998 for year 1998, and yday start with 1 (not 0).
strftime(format)
Returns formatted string from the time object. Format specifiers are as follows:
%A
%a
%B
%b
%c
%d
%H
%I
%j
%M
%m
%p
%S
%U
%W
%w
%X
%x
%Y
%y
%Z
%%
to_a
Converts tm struct into an array, whose elements are in order of:
to_f
Converts the time (in seconds from the epoch) into a floating-point number.
usec
tv_usec
Returns micro second part of the time object.