Returns true
if self
is a Thursday, false
otherwise.
Returns the Julian start date for calendar reform; if not an infinity, the returned value is suitable for passing to Date#jd
:
d = Date.new(2001, 2, 3, Date::ITALY) s = d.start # => 2299161.0 Date.jd(s).to_s # => "1582-10-15" d = Date.new(2001, 2, 3, Date::ENGLAND) s = d.start # => 2361222.0 Date.jd(s).to_s # => "1752-09-14" Date.new(2001, 2, 3, Date::GREGORIAN).start # => -Infinity Date.new(2001, 2, 3, Date::JULIAN).start # => Infinity
See argument start.
Returns a string representation of the date in self
, formatted according the given format
:
Date.new(2001, 2, 3).strftime # => "2001-02-03"
For other formats, see Formats for Dates and Times.
Equivalent to strftime
with argument '%a %b %e %T %Y'
(or its shorthand form '%c'
):
Date.new(2001, 2, 3).asctime # => "Sat Feb 3 00:00:00 2001"
See asctime.
Equivalent to strftime
with argument '%a %b %e %T %Y'
(or its shorthand form '%c'
):
Date.new(2001, 2, 3).asctime # => "Sat Feb 3 00:00:00 2001"
See asctime.
Creates a DateTime
object denoting the given week date.
DateTime.commercial(2001) #=> #<DateTime: 2001-01-01T00:00:00+00:00 ...> DateTime.commercial(2002) #=> #<DateTime: 2001-12-31T00:00:00+00:00 ...> DateTime.commercial(2001,5,6,4,5,6,'+7') #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
Returns a string representation of self
, formatted according the given +format:
DateTime.now.strftime # => "2022-07-01T11:03:19-05:00"
For other formats, see Formats for Dates and Times:
With no argument given:
Returns self
if self
is a local time.
Otherwise returns a new Time
in the user’s local timezone:
t = Time.utc(2000, 1, 1, 20, 15, 1) # => 2000-01-01 20:15:01 UTC t.localtime # => 2000-01-01 14:15:01 -0600
With argument zone
given, returns the new Time
object created by converting self
to the given time zone:
t = Time.utc(2000, 1, 1, 20, 15, 1) # => 2000-01-01 20:15:01 UTC t.localtime("-09:00") # => 2000-01-01 11:15:01 -0900
For forms of argument zone
, see Timezone Specifiers.
Returns self
, converted to the UTC timezone:
t = Time.new(2000) # => 2000-01-01 00:00:00 -0600 t.utc? # => false t.utc # => 2000-01-01 06:00:00 UTC t.utc? # => true
Related: Time#getutc
(returns a new converted Time
object).
Returns a string representation of self
, formatted by strftime('%a %b %e %T %Y')
or its shorthand version strftime('%c')
; see Formats for Dates and Times:
t = Time.new(2000, 12, 31, 23, 59, 59, 0.5) t.ctime # => "Sun Dec 31 23:59:59 2000" t.strftime('%a %b %e %T %Y') # => "Sun Dec 31 23:59:59 2000" t.strftime('%c') # => "Sun Dec 31 23:59:59 2000"
Related: Time#to_s
, Time#inspect
:
t.inspect # => "2000-12-31 23:59:59.5 +000001" t.to_s # => "2000-12-31 23:59:59 +0000"
Returns a string representation of self
, formatted by strftime('%a %b %e %T %Y')
or its shorthand version strftime('%c')
; see Formats for Dates and Times:
t = Time.new(2000, 12, 31, 23, 59, 59, 0.5) t.ctime # => "Sun Dec 31 23:59:59 2000" t.strftime('%a %b %e %T %Y') # => "Sun Dec 31 23:59:59 2000" t.strftime('%c') # => "Sun Dec 31 23:59:59 2000"
Related: Time#to_s
, Time#inspect
:
t.inspect # => "2000-12-31 23:59:59.5 +000001" t.to_s # => "2000-12-31 23:59:59 +0000"
Returns the integer second of the minute for self
, in range (0..60):
t = Time.new(2000, 1, 2, 3, 4, 5, 6) # => 2000-01-02 03:04:05 +000006 t.sec # => 5
Note: the second value may be 60 when there is a leap second.
Returns the integer month of the year for self
, in range (1..12):
t = Time.new(2000, 1, 2, 3, 4, 5, 6) # => 2000-01-02 03:04:05 +000006 t.mon # => 1
Returns the integer month of the year for self
, in range (1..12):
t = Time.new(2000, 1, 2, 3, 4, 5, 6) # => 2000-01-02 03:04:05 +000006 t.mon # => 1
Returns the integer year for self
:
t = Time.new(2000, 1, 2, 3, 4, 5, 6) # => 2000-01-02 03:04:05 +000006 t.year # => 2000
Returns the string name of the time zone for self
:
Time.utc(2000, 1, 1).zone # => "UTC" Time.new(2000, 1, 1).zone # => "Central Standard Time"
Returns true
if self
represents a Monday, false
otherwise:
t = Time.utc(2000, 1, 3) # => 2000-01-03 00:00:00 UTC t.monday? # => true
Related: Time#tuesday?
, Time#wednesday?
, Time#thursday?
.
Returns true
if self
represents a Thursday, false
otherwise:
t = Time.utc(2000, 1, 6) # => 2000-01-06 00:00:00 UTC t.thursday? # => true
Related: Time#friday?
, Time#saturday?
, Time#sunday?
.
Returns the number of microseconds in the subseconds part of self
in the range (0..999_999); lower-order digits are truncated, not rounded:
t = Time.now # => 2022-07-11 14:59:47.5484697 -0500 t.usec # => 548469
Related: Time#subsec
(returns exact subseconds).
Returns the number of nanoseconds in the subseconds part of self
in the range (0..999_999_999); lower-order digits are truncated, not rounded:
t = Time.now # => 2022-07-11 15:04:53.3219637 -0500 t.nsec # => 321963700
Related: Time#subsec
(returns exact subseconds).
Returns the exact subseconds for self
as a Numeric
(Integer
or Rational
):
t = Time.now # => 2022-07-11 15:11:36.8490302 -0500 t.subsec # => (4245151/5000000)
If the subseconds is zero, returns integer zero:
t = Time.new(2000, 1, 1, 2, 3, 4) # => 2000-01-01 02:03:04 -0600 t.subsec # => 0