Ruby - Time Methods and Attributes


Time Object Methods Used to Access Date/Time Attributes

Method What the Method Returns
hour A number representing the hour in 24-hour format ( 21 for 9 p.m., for example).
minThe number of minutes past the hour.
secThe number of seconds past the minute.
usecThe number of microseconds past the second (there are 1,000,000 microseconds per second).
dayThe number of the day in the month.
mday Synonym for the day method, considered to be "month" day.
wday The number of the day in terms of the week (Sunday is 0, Saturday is 6).
yday The number of the day in terms of the year.
month The number of the month of the date (11 for November, for example).
year The year associated with the date.
zone Returns the name of the time zone associated with the time.
utc? Returns true or false depending on if the time/date is in the UTC/GMT time zone or not.
gmt? Synonym for the utc? method for those who prefer to use the term GMT.

These methods are for retrieving attributes from a date or time, and cannot be used to set them.

To change elements of a date or time, you'll either need to add or subtract seconds, or construct a new Time object using or Time.local.