Class: Time
Class Method Summary (collapse)
-
+ _load
Unmarshal a dumped Time object.
- + alloc
- + at
-
+ gm
Creates a time based on given values, interpreted as UTC (GMT).
-
+ local
Same as Time::gm, but interprets the values in the local time zone.
-
+ mktime
Same as Time::gm, but interprets the values in the local time zone.
-
+ new
:nodoc:.
-
+ now
:nodoc:.
-
+ utc
Creates a time based on given values, interpreted as UTC (GMT).
Instance Method Summary (collapse)
-
- +
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.
-
- _dump
Dump time for marshaling.
-
- asctime
Returns a canonical string representation of time.
-
- 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.
-
- dup
Produces a shallow copy of obj---the instance variables of obj are copied, but not the objects they reference.
-
- eql?
Return true if time and other_time are both Time objects with the same seconds and fractional seconds.
-
- friday?
Returns true if time represents Friday.
-
- 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.
-
- 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.
-
- new
constructor
Returns a Time object initialized to the current system time.
-
- initialize_copy
:nodoc:.
-
- inspect
Returns a string representing time.
-
- isdst
Returns true if time occurs during Daylight Saving Time in its 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.
-
- mon
Returns the month of the year (1..12) for time.
-
- monday?
Returns true if time represents Monday.
-
- month
Returns the month of the year (1..12) for time.
-
- nsec
Returns just the number of nanoseconds for time.
-
- saturday?
Returns true if time represents Saturday.
-
- 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.
-
- succ
Return a new time object, one second later than time.
-
- sunday?
Returns true if time represents Sunday.
-
- thursday?
Returns true if time represents Thursday.
-
- to_a
Returns a ten-element array of values for time: sec, min, hour, day, month, year, wday, yday, isdst, zone ].
- - to_f
-
- to_i
Returns the value of time as an integer number of seconds since the Epoch.
-
- to_s
Returns a string representing time.
-
- tuesday?
Returns true if time represents Tuesday.
-
- tv_nsec
Returns just the number of nanoseconds for time.
-
- tv_sec
Returns the value of time as an integer number of seconds since the 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?
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.
-
- wednesday?
Returns true if time represents Wednesday.
-
- 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.
Methods included from Comparable
Methods inherited from NSDate
#compare:, date, #dateByAddingTimeInterval:, dateWithTimeInterval:sinceDate:, dateWithTimeIntervalSince1970:, dateWithTimeIntervalSinceNow:, dateWithTimeIntervalSinceReferenceDate:, #description, #descriptionWithLocale:, distantFuture, distantPast, #earlierDate:, #init, #initWithTimeInterval:sinceDate:, #initWithTimeIntervalSince1970:, #initWithTimeIntervalSinceNow:, #initWithTimeIntervalSinceReferenceDate:, #isEqualToDate:, #laterDate:, #timeIntervalSince1970, #timeIntervalSinceDate:, #timeIntervalSinceNow, timeIntervalSinceReferenceDate, #timeIntervalSinceReferenceDate
Methods inherited from NSObject
#!, #!=, #!~, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #enum_for, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_dup, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version
Constructor Details
- (Time) new
Returns a Time object initialized to the current system time. Note: The object created will be created using the resolution available on your system clock, and so may include fractional seconds.
a = Time.new #=> 2007-11-19 07:50:02 -0600
b = Time.new #=> 2007-11-19 07:50:02 -0600
a == b #=> false
"%.6f" % a.to_f #=> "1195480202.282373"
"%.6f" % b.to_f #=> "1195480202.283415"
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class NSObject
Class Method Details
+ (Object) alloc
+ (Object) at
+ (Time) utc(year) + (Time) utc(year, month) + (Time) utc(year, month, day) + (Time) utc(year, month, day, hour) + (Time) utc(year, month, day, hour, min) + (Time) utc(year, month, day, hour, min, sec_with_frac) + (Time) utc(year, month, day, hour, min, sec, usec_with_frac) + (Time) utc(sec, min, hour, day, month, year, wday, yday, isdst, tz) + (Time) gm(year) + (Time) gm(year, month) + (Time) gm(year, month, day) + (Time) gm(year, month, day, hour) + (Time) gm(year, month, day, hour, min) + (Time) gm(year, month, day, hour, min, sec_with_frac) + (Time) gm(year, month, day, hour, min, sec, usec_with_frac) + (Time) gm(sec, min, hour, day, month, year, wday, yday, isdst, tz)
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. sec_with_frac and usec_with_frac can have a fractional part.
Time.utc(2000,"jan",1,20,15,1) #=> 2000-01-01 20:15:01 UTC
Time.gm(2000,"jan",1,20,15,1) #=> 2000-01-01 20:15:01 UTC
+ (Time) local(year) + (Time) local(year, month) + (Time) local(year, month, day) + (Time) local(year, month, day, hour) + (Time) local(year, month, day, hour, min) + (Time) local(year, month, day, hour, min, sec_with_frac) + (Time) local(year, month, day, hour, min, sec, usec_with_frac) + (Time) local(sec, min, hour, day, month, year, wday, yday, isdst, tz) + (Time) mktime(year) + (Time) mktime(year, month) + (Time) mktime(year, month, day) + (Time) mktime(year, month, day, hour) + (Time) mktime(year, month, day, hour, min) + (Time) mktime(year, month, day, hour, min, sec_with_frac) + (Time) mktime(year, month, day, hour, min, sec, usec_with_frac) + (Time) mktime(sec, min, hour, day, month, year, wday, yday, isdst, tz)
Same as Time::gm, but interprets the values in the local time zone.
Time.local(2000,"jan",1,20,15,1) #=> 2000-01-01 20:15:01 -0600
+ (Time) local(year) + (Time) local(year, month) + (Time) local(year, month, day) + (Time) local(year, month, day, hour) + (Time) local(year, month, day, hour, min) + (Time) local(year, month, day, hour, min, sec_with_frac) + (Time) local(year, month, day, hour, min, sec, usec_with_frac) + (Time) local(sec, min, hour, day, month, year, wday, yday, isdst, tz) + (Time) mktime(year) + (Time) mktime(year, month) + (Time) mktime(year, month, day) + (Time) mktime(year, month, day, hour) + (Time) mktime(year, month, day, hour, min) + (Time) mktime(year, month, day, hour, min, sec_with_frac) + (Time) mktime(year, month, day, hour, min, sec, usec_with_frac) + (Time) mktime(sec, min, hour, day, month, year, wday, yday, isdst, tz)
Same as Time::gm, but interprets the values in the local time zone.
Time.local(2000,"jan",1,20,15,1) #=> 2000-01-01 20:15:01 -0600
+ (Object) new
:nodoc:
+ (Object) now
:nodoc:
+ (Time) utc(year) + (Time) utc(year, month) + (Time) utc(year, month, day) + (Time) utc(year, month, day, hour) + (Time) utc(year, month, day, hour, min) + (Time) utc(year, month, day, hour, min, sec_with_frac) + (Time) utc(year, month, day, hour, min, sec, usec_with_frac) + (Time) utc(sec, min, hour, day, month, year, wday, yday, isdst, tz) + (Time) gm(year) + (Time) gm(year, month) + (Time) gm(year, month, day) + (Time) gm(year, month, day, hour) + (Time) gm(year, month, day, hour, min) + (Time) gm(year, month, day, hour, min, sec_with_frac) + (Time) gm(year, month, day, hour, min, sec, usec_with_frac) + (Time) gm(sec, min, hour, day, month, year, wday, yday, isdst, tz)
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. sec_with_frac and usec_with_frac can have a fractional part.
Time.utc(2000,"jan",1,20,15,1) #=> 2000-01-01 20:15:01 UTC
Time.gm(2000,"jan",1,20,15,1) #=> 2000-01-01 20:15:01 UTC
Instance Method Details
- (Time) +(numeric)
Addition---Adds some number of seconds (possibly fractional) to time and returns that value as a new time.
t = Time.now #=> 2007-11-19 08:22:21 -0600
t + (60 * 60 * 24) #=> 2007-11-20 08:22:21 -0600
- (Float) -(other_time) - (Time) -(numeric)
Difference---Returns a new time that represents the difference between two times, or subtracts the given number of seconds in numeric from time.
t = Time.now #=> 2007-11-19 08:23:10 -0600
t2 = t + 2592000 #=> 2007-12-19 08:23:10 -0600
t2 - t #=> 2592000.0
t2 - 2592000 #=> 2007-11-19 08:23:10 -0600
- (-1, ...) <=>(other_time)
Comparison---Compares time with other_time.
t = Time.now #=> 2007-11-19 08:12:12 -0600
t2 = t + 2592000 #=> 2007-12-19 08:12:12 -0600
t <=> t2 #=> -1
t2 <=> t #=> 1
t = Time.now #=> 2007-11-19 08:13:38 -0600
t2 = t + 0.1 #=> 2007-11-19 08:13:38 -0600
t.nsec #=> 98222999
t2.nsec #=> 198222999
t <=> t2 #=> -1
t2 <=> t #=> 1
t <=> t #=> 0
- (String) _dump
Dump time for marshaling.
- (String) asctime - (String) ctime
Returns a canonical string representation of time.
Time.now.asctime #=> "Wed Apr 9 08:56:03 2003"
- (String) asctime - (String) ctime
Returns a canonical string representation of time.
Time.now.asctime #=> "Wed Apr 9 08:56:03 2003"
- (Fixnum) day - (Fixnum) mday
Returns the day of the month (1..n) for time.
t = Time.now #=> 2007-11-19 08:27:03 -0600
t.day #=> 19
t.mday #=> 19
- (Boolean) isdst - (Boolean) dst?
Returns true if time occurs during Daylight Saving Time in its time zone.
# CST6CDT:
Time.local(2000, 1, 1).zone #=> "CST"
Time.local(2000, 1, 1).isdst #=> false
Time.local(2000, 1, 1).dst? #=> false
Time.local(2000, 7, 1).zone #=> "CDT"
Time.local(2000, 7, 1).isdst #=> true
Time.local(2000, 7, 1).dst? #=> true
# Asia/Tokyo:
Time.local(2000, 1, 1).zone #=> "JST"
Time.local(2000, 1, 1).isdst #=> false
Time.local(2000, 1, 1).dst? #=> false
Time.local(2000, 7, 1).zone #=> "JST"
Time.local(2000, 7, 1).isdst #=> false
Time.local(2000, 7, 1).dst? #=> false
- (Object) dup
Produces a shallow copy of obj---the instance variables of obj are copied, but not the objects they reference. dup copies the tainted state of obj. See also the discussion under Object#clone. In general, clone and dup may have different semantics in descendant classes. While clone is used to duplicate an object, including its internal state, dup typically uses the class of the descendant object to create the new instance.
This method may have class-specific behavior. If so, that behavior will be documented under the #initialize_copy method of the class.
- (Boolean) eql?(other_time)
Return true if time and other_time are both Time objects with the same seconds and fractional seconds.
- (Boolean) friday?
Returns true if time represents Friday.
t = Time.local(1987, 12, 18) #=> 1987-12-18 00:00:00 -0600
t.friday? #=> true
- (Time) getgm - (Time) getutc
Returns a new new_time object representing time in UTC.
t = Time.local(2000,1,1,20,15,1) #=> 2000-01-01 20:15:01 -0600
t.gmt? #=> false
y = t.getgm #=> 2000-01-02 02:15:01 UTC
y.gmt? #=> true
t == y #=> true
- (Time) getlocal
Returns a new new_time object representing time in local time (using the local time zone in effect for this process).
t = Time.gm(2000,1,1,20,15,1) #=> 2000-01-01 20:15:01 UTC
t.gmt? #=> true
l = t.getlocal #=> 2000-01-01 14:15:01 -0600
l.gmt? #=> false
t == l #=> true
- (Time) getgm - (Time) getutc
Returns a new new_time object representing time in UTC.
t = Time.local(2000,1,1,20,15,1) #=> 2000-01-01 20:15:01 -0600
t.gmt? #=> false
y = t.getgm #=> 2000-01-02 02:15:01 UTC
y.gmt? #=> true
t == y #=> true
- (Boolean) utc? - (Boolean) gmt?
Returns true if time represents a time in UTC (GMT).
t = Time.now #=> 2007-11-19 08:15:23 -0600
t.utc? #=> false
t = Time.gm(2000,"jan",1,20,15,1) #=> 2000-01-01 20:15:01 UTC
t.utc? #=> true
t = Time.now #=> 2007-11-19 08:16:03 -0600
t.gmt? #=> false
t = Time.gm(2000,1,1,20,15,1) #=> 2000-01-01 20:15:01 UTC
t.gmt? #=> true
- (Fixnum) gmt_offset - (Fixnum) gmtoff - (Fixnum) utc_offset
Returns the offset in seconds between the timezone of time and UTC.
t = Time.gm(2000,1,1,20,15,1) #=> 2000-01-01 20:15:01 UTC
t.gmt_offset #=> 0
l = t.getlocal #=> 2000-01-01 14:15:01 -0600
l.gmt_offset #=> -21600
- (Time) gmtime - (Time) utc
Converts time to UTC (GMT), modifying the receiver.
t = Time.now #=> 2007-11-19 08:18:31 -0600
t.gmt? #=> false
t.gmtime #=> 2007-11-19 14:18:31 UTC
t.gmt? #=> true
t = Time.now #=> 2007-11-19 08:18:51 -0600
t.utc? #=> false
t.utc #=> 2007-11-19 14:18:51 UTC
t.utc? #=> true
- (Fixnum) gmt_offset - (Fixnum) gmtoff - (Fixnum) utc_offset
Returns the offset in seconds between the timezone of time and UTC.
t = Time.gm(2000,1,1,20,15,1) #=> 2000-01-01 20:15:01 UTC
t.gmt_offset #=> 0
l = t.getlocal #=> 2000-01-01 14:15:01 -0600
l.gmt_offset #=> -21600
- (Fixnum) hash
Return a hash code for this time object.
- (Fixnum) hour
Returns the hour of the day (0..23) for time.
t = Time.now #=> 2007-11-19 08:26:20 -0600
t.hour #=> 8
- (Object) initialize_copy
:nodoc:
- (String) inspect - (String) to_s
Returns a string representing time. Equivalent to calling Time#strftime with a format string of "%Y-%m-%d %H:%M:%S %z" for a local time and "%Y-%m-%d %H:%M:%S UTC" for a UTC time.
Time.now.to_s #=> "2007-10-05 16:09:51 +0900"
Time.now.utc.to_s #=> "2007-10-05 07:09:51 UTC"
- (Boolean) isdst - (Boolean) dst?
Returns true if time occurs during Daylight Saving Time in its time zone.
# CST6CDT:
Time.local(2000, 1, 1).zone #=> "CST"
Time.local(2000, 1, 1).isdst #=> false
Time.local(2000, 1, 1).dst? #=> false
Time.local(2000, 7, 1).zone #=> "CDT"
Time.local(2000, 7, 1).isdst #=> true
Time.local(2000, 7, 1).dst? #=> true
# Asia/Tokyo:
Time.local(2000, 1, 1).zone #=> "JST"
Time.local(2000, 1, 1).isdst #=> false
Time.local(2000, 1, 1).dst? #=> false
Time.local(2000, 7, 1).zone #=> "JST"
Time.local(2000, 7, 1).isdst #=> false
Time.local(2000, 7, 1).dst? #=> false
- (Time) localtime
Converts time to local time (using the local time zone in effect for this process) modifying the receiver.
t = Time.gm(2000, "jan", 1, 20, 15, 1) #=> 2000-01-01 20:15:01 UTC
t.gmt? #=> true
t.localtime #=> 2000-01-01 14:15:01 -0600
t.gmt? #=> false
- (Object) marshal_dump
undocumented
- (Object) marshal_load
undocumented
- (Fixnum) day - (Fixnum) mday
Returns the day of the month (1..n) for time.
t = Time.now #=> 2007-11-19 08:27:03 -0600
t.day #=> 19
t.mday #=> 19
- (Fixnum) min
Returns the minute of the hour (0..59) for time.
t = Time.now #=> 2007-11-19 08:25:51 -0600
t.min #=> 25
- (Fixnum) mon - (Fixnum) month
Returns the month of the year (1..12) for time.
t = Time.now #=> 2007-11-19 08:27:30 -0600
t.mon #=> 11
t.month #=> 11
- (Boolean) monday?
Returns true if time represents Monday.
t = Time.local(2003, 8, 4) #=> 2003-08-04 00:00:00 -0500
p t.monday? #=> true
- (Fixnum) mon - (Fixnum) month
Returns the month of the year (1..12) for time.
t = Time.now #=> 2007-11-19 08:27:30 -0600
t.mon #=> 11
t.month #=> 11
- (Integer) nsec - (Integer) tv_nsec
Returns just the number of nanoseconds for time.
t = Time.now #=> 2007-11-17 15:18:03 +0900
"%10.9f" % t.to_f #=> "1195280283.536151409"
t.nsec #=> 536151406
The lowest digit of to_f and nsec is different because IEEE 754 double is not accurate enough to represent nanoseconds from the Epoch. The accurate value is returned by nsec.
- (Boolean) saturday?
Returns true if time represents Saturday.
t = Time.local(2006, 6, 10) #=> 2006-06-10 00:00:00 -0500
t.saturday? #=> true
- (Fixnum) 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.
t = Time.now #=> 2007-11-19 08:25:02 -0600
t.sec #=> 2
- (String) strftime(string)
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.
Format meaning:
a - The abbreviated weekday name (``Sun'')
A - The full weekday name (``Sunday'')
b - The abbreviated month name (``Jan'')
B - The full month name (``January'')
c - The preferred local date and time representation
d - Day of the month (01..31)
H - Hour of the day, 24-hour clock (00..23)
I - Hour of the day, 12-hour clock (01..12)
j - Day of the year (001..366)
m - Month of the year (01..12)
M - Minute of the hour (00..59)
p - Meridian indicator (``AM'' or ``PM'')
S - Second of the minute (00..60)
U - Week number of the current year,
starting with the first Sunday as the first
day of the first week (00..53)
%W - Week number of the current year,
starting with the first Monday as the first
day of the first week (00..53)
%w - Day of the week (Sunday is 0, 0..6)
%x - Preferred representation for the date alone, no time
X - Preferred representation for the time alone, no date
y - Year without a century (00..99)
Y - Year with century
Z - Time zone name
%% - Literal ``%'' character
t = Time.now #=> 2007-11-19 08:37:48 -0600
t.strftime("Printed on %m/%d/%Y") #=> "Printed on 11/19/2007"
t.strftime("at %I:%M%p") #=> "at 08:37AM"
- (Time) succ
Return a new time object, one second later than time.
t = Time.now #=> 2007-11-19 08:23:57 -0600
t.succ #=> 2007-11-19 08:23:58 -0600
- (Boolean) sunday?
Returns true if time represents Sunday.
t = Time.local(1990, 4, 1) #=> 1990-04-01 00:00:00 -0600
t.sunday? #=> true
- (Boolean) thursday?
Returns true if time represents Thursday.
t = Time.local(1995, 12, 21) #=> 1995-12-21 00:00:00 -0600
p t.thursday? #=> true
- (Array) 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.
t = Time.now #=> 2007-11-19 08:36:01 -0600
now = t.to_a #=> [1, 36, 8, 19, 11, 2007, 1, 323, false, "CST"]
- (Object) to_f
- (Integer) to_i - (Integer) tv_sec
Returns the value of time as an integer number of seconds since the Epoch.
t = Time.now
"%10.5f" % t.to_f #=> "1049896564.17839"
t.to_i #=> 1049896564
- (String) inspect - (String) to_s
Returns a string representing time. Equivalent to calling Time#strftime with a format string of "%Y-%m-%d %H:%M:%S %z" for a local time and "%Y-%m-%d %H:%M:%S UTC" for a UTC time.
Time.now.to_s #=> "2007-10-05 16:09:51 +0900"
Time.now.utc.to_s #=> "2007-10-05 07:09:51 UTC"
- (Boolean) tuesday?
Returns true if time represents Tuesday.
t = Time.local(1991, 2, 19) #=> 1991-02-19 00:00:00 -0600
p t.tuesday? #=> true
- (Integer) nsec - (Integer) tv_nsec
Returns just the number of nanoseconds for time.
t = Time.now #=> 2007-11-17 15:18:03 +0900
"%10.9f" % t.to_f #=> "1195280283.536151409"
t.nsec #=> 536151406
The lowest digit of to_f and nsec is different because IEEE 754 double is not accurate enough to represent nanoseconds from the Epoch. The accurate value is returned by nsec.
- (Integer) to_i - (Integer) tv_sec
Returns the value of time as an integer number of seconds since the Epoch.
t = Time.now
"%10.5f" % t.to_f #=> "1049896564.17839"
t.to_i #=> 1049896564
- (Integer) usec - (Integer) tv_usec
Returns just the number of microseconds for time.
t = Time.now #=> 2007-11-19 08:03:26 -0600
"%10.6f" % t.to_f #=> "1195481006.775195"
t.usec #=> 775195
- (Integer) usec - (Integer) tv_usec
Returns just the number of microseconds for time.
t = Time.now #=> 2007-11-19 08:03:26 -0600
"%10.6f" % t.to_f #=> "1195481006.775195"
t.usec #=> 775195
- (Time) gmtime - (Time) utc
Converts time to UTC (GMT), modifying the receiver.
t = Time.now #=> 2007-11-19 08:18:31 -0600
t.gmt? #=> false
t.gmtime #=> 2007-11-19 14:18:31 UTC
t.gmt? #=> true
t = Time.now #=> 2007-11-19 08:18:51 -0600
t.utc? #=> false
t.utc #=> 2007-11-19 14:18:51 UTC
t.utc? #=> true
- (Boolean) utc? - (Boolean) gmt?
Returns true if time represents a time in UTC (GMT).
t = Time.now #=> 2007-11-19 08:15:23 -0600
t.utc? #=> false
t = Time.gm(2000,"jan",1,20,15,1) #=> 2000-01-01 20:15:01 UTC
t.utc? #=> true
t = Time.now #=> 2007-11-19 08:16:03 -0600
t.gmt? #=> false
t = Time.gm(2000,1,1,20,15,1) #=> 2000-01-01 20:15:01 UTC
t.gmt? #=> true
- (Fixnum) gmt_offset - (Fixnum) gmtoff - (Fixnum) utc_offset
Returns the offset in seconds between the timezone of time and UTC.
t = Time.gm(2000,1,1,20,15,1) #=> 2000-01-01 20:15:01 UTC
t.gmt_offset #=> 0
l = t.getlocal #=> 2000-01-01 14:15:01 -0600
l.gmt_offset #=> -21600
- (Fixnum) wday
Returns an integer representing the day of the week, 0..6, with Sunday == 0.
t = Time.now #=> 2007-11-20 02:35:35 -0600
t.wday #=> 2
t.sunday? #=> false
t.monday? #=> false
t.tuesday? #=> true
t.wednesday? #=> false
t.thursday? #=> false
t.friday? #=> false
t.saturday? #=> false
- (Boolean) wednesday?
Returns true if time represents Wednesday.
t = Time.local(1993, 2, 24) #=> 1993-02-24 00:00:00 -0600
p t.wednesday? #=> true
- (Fixnum) yday
Returns an integer representing the day of the year, 1..366.
t = Time.now #=> 2007-11-19 08:32:31 -0600
t.yday #=> 323
- (Fixnum) year
Returns the year for time (including the century).
t = Time.now #=> 2007-11-19 08:27:51 -0600
t.year #=> 2007
- (String) zone
Returns the name of the time zone used for time. As of Ruby 1.8, returns "UTC" rather than "GMT" for UTC times.
t = Time.gm(2000, "jan", 1, 20, 15, 1)
t.zone #=> "UTC"
t = Time.local(2000, "jan", 1, 20, 15, 1)
t.zone #=> "CST"