Class

Time

Extends:

Includes:

Time is an abstraction of dates and times. Time is stored internally as the number of seconds and microseconds since the epoch, January 1, 1970 00:00 UTC. On some operating systems, this offset is allowed to be negative. Also see the library modules Date and ParseDate. The Time class treats GMT (Greenwich Mean Time) and UTC (Coordinated Universal Time)[Yes, UTC really does stand for Coordinated Universal Time. There was a committee involved.] as equivalent. GMT is the older way of referring to these baseline times but persists in the names of calls on Posix systems.

All times are stored with some number of microseconds. Be aware of this fact when comparing times with each other—times that are apparently equal when displayed may be different when compared.

Public Methods
+ Addition—Adds some number of seconds (possibly fractional) to time and returns that value as a new time.
- Difference—Returns a new time that represents the difference between two times, or subtracts the given number of seconds in numeric from time.
<=> Comparison—Compares time with other_time or with numeric, which is the number of seconds (possibly fractional) since epoch.
_dump Dump time for marshaling.
_load Unmarshal a dumped Time object.
asctime Returns a canonical string representation of time.
at Creates a new time object with the value given by aTime, or the given number of seconds (and optional microseconds) from epoch. A non-portable feature allows the offset to be negative on some systems.
ctime Returns a canonical string representation of time.
day Returns the day of the month (1..n) for time.
dst? Returns true if time occurs during Daylight Saving Time in its time zone.
eql? Return true if time and other_time are both Time objects with the same seconds and fractional seconds.
getgm Returns a new new_time object representing time in UTC.
getlocal Returns a new new_time object representing time in local time (using the local time zone in effect for this process).
getutc Returns a new new_time object representing time in UTC.
gm Creates a time 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.
gmt? Returns true if time represents a time in UTC (GMT).
gmt_offset Returns the offset in seconds between the timezone of time and UTC.
gmtime Converts time to UTC (GMT), modifying the receiver.
gmtoff Returns the offset in seconds between the timezone of time and UTC.
hash Return a hash code for this time object.
hour Returns the hour of the day (0..23) for time.
inspect Returns a string representing time. Equivalent to calling Time#strftime with a format string of ``%a %b %d %H:%M:%S %Z %Y’’.
isdst Returns true if time occurs during Daylight Saving Time in its time zone.
local Same as Time::gm, but interprets the values in the local time zone.
localtime Converts time to local time (using the local time zone in effect for this process) modifying the receiver.
marshal_dump undocumented
marshal_load undocumented
mday Returns the day of the month (1..n) for time.
min Returns the minute of the hour (0..59) for time.
mktime Same as Time::gm, but interprets the values in the local time zone.
mon Returns the month of the year (1..12) for time.
month Returns the month of the year (1..12) for time.
new Document-method: now
now Synonym for Time.new. Returns a Time object initialized tot he current system time.
sec Returns the second of the minute (0..60)[Yes, seconds really can range from zero to 60. This allows the system to inject leap seconds every now and then to correct for the fact that years are not really a convenient number of hours long.] for time.
strftime Formats time according to the directives in the given format string. Any text not listed as a directive will be passed through to the output string.
succ Return a new time object, one second later than time.
times Deprecated in favor of Process::times
to_a Returns a ten-element array of values for time: {[ sec, min, hour, day, month, year, wday, yday, isdst, zone ]}. See the individual methods for an explanation of the valid ranges of each value. The ten elements can be passed directly to Time::utc or Time::local to create a new Time.
to_f Returns the value of time as a floating point number of seconds since epoch.
to_i Returns the value of time as an integer number of seconds since epoch.
to_s Returns a string representing time. Equivalent to calling Time#strftime with a format string of ``%a %b %d %H:%M:%S %Z %Y’’.
tv_sec Returns the value of time as an integer number of seconds since epoch.
tv_usec Returns just the number of microseconds for time.
usec Returns just the number of microseconds for time.
utc Converts time to UTC (GMT), modifying the receiver.
utc Creates a time 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.
utc? Returns true if time represents a time in UTC (GMT).
utc_offset Returns the offset in seconds between the timezone of time and UTC.
wday Returns an integer representing the day of the week, 0..6, with Sunday == 0.
yday Returns an integer representing the day of the year, 1..366.
year Returns the year for time (including the century).
zone Returns the name of the time zone used for time. As of Ruby 1.8, returns ``UTC’’ rather than ``GMT’’ for UTC times.
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.