Ruby/Time/Time class

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск

Time Introduction

puts Time.now                                   
puts Time.at(0)                                 
puts t = Time.at(0)
puts t.sec                                      
puts t.min                                      
puts t.hour                                     
puts t.day                                      
puts t.month                                    
puts t.year                                     
puts t.wday                                     
puts t.yday                                     
puts t.isdst                                    
puts t.zone



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).
min         The number of minutes past the hour.
sec         The number of seconds past the minute.
usec        The number of microseconds past the second (there are 1,000,000 microseconds per second).
day         The 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.



Time represented internally as seconds since the (platform-dependent) epoch

t = Time.now.to_i    # => 1184036194 seconds since epoch
Time.at(t)           # => seconds since epoch to Time object
t = Time.now.to_f    # => 1184036322.90872: includes 908720 microseconds
Time.at(0)           # => Wed Dec 31 16:00:00 -0800 1969: epoch in local time