Ruby 2.2.0 リファレンスマニュアル > ライブラリ一覧 > 組み込みライブラリ > Timeクラス
クラスの継承リスト: Time < Comparable < Object < Kernel < BasicObject
時刻を表すクラスです。
Time.now は現在の時刻を返します。 File.mtime などが返すファイルのタイムスタンプは Time オブジェクトです。
Time オブジェクトは時刻を起算時からの経過秒数で保持しています。 起算時は協定世界時(UTC、もしくはその旧称から GMT とも表記されます) の 1970年1月1日午前0時です。なお、うるう秒を勘定するかどうかはシステムに よります。
Time オブジェクトが格納可能な時刻の範囲は環境によって異なっていましたが、 Ruby 1.9.2 からは OS の制限の影響を受けません。
また、Time オブジェクトは協定世界時と地方時のどちらのタイムゾー ンを使用するかのフラグを内部に保持しています。 タイムゾーンのフラグは Marshal データに保持されます。
p Marshal.load(Marshal.dump(Time.now.gmtime)).zone
# => "UTC"
time ライブラリによって、Time.parse, Time.rfc2822, Time.httpdate, Time.iso8601 等が拡張されます。
Ruby 1.9.2 以降の Time クラスのデザインの詳細は https://staff.aist.go.jp/tanaka-akira/pub/sapporo-rubykaigi-02-akr-2009.pdf や 「APIデザインケーススタディ」(https://gihyo.jp/book/2016/978-4-7741-7802-8) の第4章を参照してください。
localtime(3) も参照してください。
C 言語の tm 構造体とは異なり、month は 1 月に対 して 1 を返し、year は 1998 年に対して 1998 を返します。また、 yday は 1 から数えます。
at(time) -> Time
[permalink][rdoc]time で指定した時刻の Time オブジェクトを返します。
引数が数値の場合、生成された Time オブジェクトのタイムゾーンは地方時となります。
Time.at(0) # => 1970-01-01 09:00:00 +0900
Time.at(Time.at(0)) # => 1970-01-01 09:00:00 +0900
Time.at(Time.at(0).getutc) # => 1970-01-01 00:00:00 UTC
Time.at(946702800) # => 2000-01-01 14:00:00 +0900
Time.at(-284061600) # => 1960-12-31 15:00:00 +0900
Time.at(946684800.2).usec # => 200000
at(time, usec) -> Time
[permalink][rdoc]time + (usec/1000000) の時刻を表す Time オブジェクトを返します。 浮動小数点の精度では不十分な場合に使用します。
生成された Time オブジェクトのタイムゾーンは地方時となります。
Time.at(946684800, 123456.789).nsec # => 123456789
gm(year, mon = 1, day = 1, hour = 0, min = 0, sec = 0, usec = 0) -> Time
[permalink][rdoc]utc(year, mon = 1, day = 1, hour = 0, min = 0, sec = 0, usec = 0) -> Time
引数で指定した協定世界時の Time オブジェクトを返します。
第2引数以降に nil を指定した場合の値はその引数がとり得る最小の値です。
p Time.gm(2000, 1, 1) # => 2000-01-01 00:00:00 UTC
gm(sec, min, hour, mday, mon, year, wday, yday, isdst, zone) -> Time
[permalink][rdoc]utc(sec, min, hour, mday, mon, year, wday, yday, isdst, zone) -> Time
引数で指定した協定世界時の Time オブジェクトを返します。
引数の順序は Time#to_a と全く同じです。 引数 wday, yday, zone に指定した値は無視されます。 引数に nil を指定した場合の値はその引数がとり得る最小の値です。
local(year, mon = 1, day = 1, hour = 0, min = 0, sec = 0, usec = 0) -> Time
[permalink][rdoc]mktime(year, mon = 1, day = 1, hour = 0, min = 0, sec = 0, usec = 0) -> Time
引数で指定した地方時の Time オブジェクトを返します。
第2引数以降に nil を指定した場合の値はその引数がとり得る最小の値です。
p Time.local(2000, 1, 1) # => 2000-01-01 00:00:00 +0900
local(sec, min, hour, mday, mon, year, wday, yday, isdst, zone) -> Time
[permalink][rdoc]mktime(sec, min, hour, mday, mon, year, wday, yday, isdst, zone) -> Time
引数で指定した地方時の Time オブジェクトを返します。
引数の順序は Time#to_a と全く同じです。 引数 wday, yday, zone に指定した値は無視されます。 引数に nil を指定した場合の値はその引数がとり得る最小の値です。
new -> Time
[permalink][rdoc]now -> Time
現在時刻の Time オブジェクトを生成して返します。 タイムゾーンは地方時となります。
p Time.now # => 2009-06-24 12:39:54 +0900
new(year, mon = nil, day = nil, hour = nil, min = nil, sec = nil, utc_offset = nil) -> Time
[permalink][rdoc]引数で指定した地方時の Time オブジェクトを返します。
mon day hour min sec に nil を指定した場合の値は、その引数がとり得る最小の値です。 utc_offset に nil を指定した場合の値は、現在のタイムゾーンに従います。
p Time.new(2008, 6, 21, 13, 30, 0, "+09:00") # => 2008-06-21 13:30:00 +0900
self + other -> Time
[permalink][rdoc]self より other 秒だけ後の時刻を返します。
p t = Time.local(2000) # => 2000-01-01 00:00:00 +0900
p t + (60 * 60 * 24) # => 2000-01-02 00:00:00 +0900
self - time -> Float
[permalink][rdoc]自身と time との時刻の差を Float で返します。単位は秒です。
p t = Time.local(2000) # => 2000-01-01 00:00:00 +0900
p t2 = t + 2592000 # => 2000-01-31 00:00:00 +0900
p t2 - t # => 2592000.0
self - sec -> Time
[permalink][rdoc]自身より sec 秒だけ前の時刻を返します。
p t = Time.local(2000) # => 2000-01-01 00:00:00 +0900
p t2 = t + 2592000 # => 2000-01-31 00:00:00 +0900
p t2 - 2592000 # => 2000-01-01 00:00:00 +0900
self <=> other -> -1 | 0 | 1 | nil
[permalink][rdoc]self と other の時刻を比較します。self の方が大きい場合は 1 を、等しい場合は 0 を、 小さい場合は -1 を返します。比較できない場合は、nil を返します。
p t = Time.local(2000) # => 2000-01-01 00:00:00 +0900
p t2 = t + 2592000 # => 2000-01-31 00:00:00 +0900
p t <=> t2 # => -1
p t2 <=> t # => 1
p t = Time.local(2000) # => 2000-01-01 00:00:00 +0900
p t2 = t + 0.1 # => 2000-01-01 00:00:00 +0900
p t.nsec # => 0
p t2.nsec # => 100000000
p t <=> t2 # => -1
p t2 <=> t # => 1
p t <=> t # => 0
asctime -> String
[permalink][rdoc]ctime -> String
時刻を asctime(3) の形式の文字列に変換します。た だし、末尾の改行文字 "\n" は含まれません。
戻り値の文字エンコーディングは Encoding::US_ASCII です。
p Time.local(2000).asctime # => "Sat Jan 1 00:00:00 2000"
p Time.local(2000).asctime.encoding # => #<Encoding:US-ASCII>
p Time.local(2000).ctime # => "Sat Jan 1 00:00:00 2000"
mday -> Integer
[permalink][rdoc]day -> Integer
日を整数で返します。
t = Time.local(2000,1,2,3,4,5) # => 2000-01-02 03:04:05 +0900
p t.day # => 2
p t.mday # => 2
isdst -> bool
[permalink][rdoc]dst? -> bool
自身が表す日時が夏時間なら true を返します。そうでないなら false を返します。
ENV['TZ'] = 'US/Pacific'
p Time.local(2000, 7, 1).isdst # => true
p Time.local(2000, 1, 1).isdst # => false
eql?(other) -> bool
[permalink][rdoc]other が Time かそのサブクラスのインスタンスであり自身と時刻が等しい場合に true を返します。そうでない場合に false を返します。
p Time.local(2000, 1, 1).eql?(Time.local(2000, 1, 1)) # => true
p Time.local(2000, 1, 1).eql?(Time.local(2000, 1, 2)) # => false
friday? -> bool
[permalink][rdoc]self の表す時刻が金曜日である場合に true を返します。 そうでない場合に false を返します。
t = Time.local(1987, 12, 18) # => 1987-12-18 00:00:00 +0900
p t.friday? # => true
getgm -> Time
[permalink][rdoc]getutc -> Time
タイムゾーンを協定世界時に設定した Time オブジェクトを新しく 生成して返します。
p t = Time.local(2000,1,1,20,15,1) #=> 2000-01-01 20:15:01 +0900
p t.gmt? #=> false
p y = t.getgm #=> 2000-01-01 11:15:01 UTC
p y.gmt? #=> true
p t == y #=> true
getlocal -> Time
[permalink][rdoc]getlocal(utc_offset) -> Time
タイムゾーンを地方時に設定した Time オブジェクトを新しく生成 して返します。
p t = Time.utc(2000,1,1,20,15,1) # => 2000-01-01 20:15:01 UTC
p t.utc? # => true
p l = t.getlocal # => 2000-01-02 05:15:01 +0900
p l.utc? # => false
p t == l # => true
p j = t.getlocal("+09:00") # => 2000-01-02 05:15:01 +0900
p j.utc? # => false
p t == j # => true
gmt? -> bool
[permalink][rdoc]utc? -> bool
self のタイムゾーンが協定世界時に設定されていれば真を返します。
p t = Time.local(2017,9,19,15,0,0) # => 2017-09-19 15:00:00 +0900
p t.utc? # => false
p utc_t = t.getutc # => 2017-09-19 06:00:00 UTC
p utc_t.utc? # => true
utc_offset -> Integer
[permalink][rdoc]gmt_offset -> Integer
gmtoff -> Integer
協定世界時との時差を秒を単位とする数値として返します。
地方時が協定世界時よりも進んでいる場合(アジア、オーストラリアなど) には正の値、遅れている場合(アメリカなど)には負の値になります。
地方時の場合
p Time.now.zone # => "JST"
p Time.now.utc_offset # => 32400
タイムゾーンが協定世界時に設定されている場合は 0 を返します。
協定世界時の場合
p Time.now.getgm.zone # => "UTC"
p Time.now.getgm.utc_offset # => 0
gmtime -> self
[permalink][rdoc]utc -> self
タイムゾーンを協定世界時に設定します。
このメソッドを呼び出した後は時刻変換を協定世界時として行ないます。
Time#localtime, Time#gmtime の挙動はシステムの localtime(3) の挙動に依存します。Time クラ スでは時刻を起算時からの経過秒数として保持していますが、ある特定の 時刻までの経過秒は、システムがうるう秒を勘定するかどうかによって異 なる場合があります。システムを越えて Time オブジェクトを受け 渡す場合には注意する必要があります。
p t = Time.local(2000,1,1,20,15,1) # => 2000-01-01 20:15:01 +0900
p t.gmt? # => false
p t.gmtime # => 2000-01-01 11:15:01 UTC
p t.gmt? # => true
hash -> Integer
[permalink][rdoc]self のハッシュ値を返します。
[SEE_ALSO] Object#hash
hour -> Integer
[permalink][rdoc]時を整数で返します。
t = Time.local(2000,1,2,3,4,5) # => 2000-01-02 03:04:05 +0900
p t.hour # => 3
localtime -> self
[permalink][rdoc]localtime(utc_offset) -> self
タイムゾーンを地方時に設定します。
このメソッドを呼び出した後は時刻変換を協定地方時として行ないます。
Time#localtime, Time#gmtime の挙動はシステムの localtime(3) の挙動に依存します。Time クラ スでは時刻を起算時からの経過秒数として保持していますが、ある特定の 時刻までの経過秒は、システムがうるう秒を勘定するかどうかによって異 なる場合があります。システムを越えて Time オブジェクトを受け 渡す場合には注意する必要があります。
p t = Time.utc(2000, "jan", 1, 20, 15, 1) # => 2000-01-01 20:15:01 UTC
p t.utc? # => true
p t.localtime # => 2000-01-02 05:15:01 +0900
p t.utc? # => false
p t.localtime("+09:00") # => 2000-01-02 05:15:01 +0900
p t.utc? # => false
min -> Integer
[permalink][rdoc]分を整数で返します。
t = Time.local(2000,1,2,3,4,5) # => 2000-01-02 03:04:05 +0900
p t.min # => 4
mon -> Integer
[permalink][rdoc]month -> Integer
月を整数で返します。
t = Time.local(2000,1,2,3,4,5) # => 2000-01-02 03:04:05 +0900
p t.month # => 1
p t.mon # => 1
monday? -> bool
[permalink][rdoc]self の表す時刻が月曜日である場合に true を返します。 そうでない場合に false を返します。
t = Time.local(2003, 8, 4) # => 2003-08-04 00:00:00 +0900
p t.monday? # => true
nsec -> Integer
[permalink][rdoc]tv_nsec -> Integer
時刻のナノ秒の部分を整数で返します。
t = Time.local(2000,1,2,3,4,5,6)
p "%10.9f" % t.to_f # => "946749845.000005960"
p t.nsec # => 6000
IEEE 754 浮動小数点数で表現できる精度が違うため、Time#to_fの最小 の桁とnsecの最小の桁は異なります。nsecで表される値の方が正確です。
round(ndigits=0) -> Time
[permalink][rdoc]十進小数点数で指定した桁数の精度で丸めをし、 その Time オブジェクトを返します。 (デフォルトは0、つまり小数点の所で丸めます)。
ndigits には 0 以上の整数を渡します。
require 'time'
t = Time.utc(1999,12,31, 23,59,59)
p((t + 0.4).round.iso8601(3)) # => "1999-12-31T23:59:59.000Z"
p((t + 0.49).round.iso8601(3)) # => "1999-12-31T23:59:59.000Z"
p((t + 0.5).round.iso8601(3)) # => "2000-01-01T00:00:00.000Z"
p((t + 1.4).round.iso8601(3)) # => "2000-01-01T00:00:00.000Z"
p((t + 1.49).round.iso8601(3)) # => "2000-01-01T00:00:00.000Z"
p((t + 1.5).round.iso8601(3)) # => "2000-01-01T00:00:01.000Z"
t = Time.utc(1999,12,31, 23,59,59)
p (t + 0.123456789).round(4).iso8601(6) # => "1999-12-31T23:59:59.123500Z"
saturday? -> bool
[permalink][rdoc]self の表す時刻が土曜日である場合に true を返します。 そうでない場合に false を返します。
t = Time.local(2006, 6, 10) # => 2006-06-10 00:00:00 +0900
p t.saturday? # => true
sec -> Integer
[permalink][rdoc]秒を整数で返します。
p Time.mktime(2000, 1, 1).sec # => 0
通常は0から59を返しますが、うるう秒の場合は60を返します。
ENV['TZ'] = 'right/UTC'
p Time.mktime(2005, 12, 31, 23, 59, 60).sec # => 60
strftime(format) -> String
[permalink][rdoc]時刻を format 文字列に従って文字列に変換した結果を返します。
このメソッドは strftime(3) や glibcの仕様を参考に作成されており、以下のオプションが利用できます。
EとOは無視されます。
例
p t = Time.new(2001,2,3,4,5,6,"+09:00") # => 2001-02-03 04:05:06 +0900
p t.strftime("Printed on %m/%d/%Y") # => "Printed on 02/03/2001"
p t.strftime("Printed on %m/%-d/%_6Y") # => "Printed on 02/3/ 2001"
p t.strftime("at %I:%M%p") # => "at 04:05AM"
p t.strftime("at %I:%M%#p") # => "at 04:05am"
様々なISO 8601形式
t = Time.new(2001,2,3,4,5,6,"+09:00")
p t.strftime("%Y%m%d") # => 20010203 Calendar date (basic)
p t.strftime("%F") # => 2001-02-03 Calendar date (extended)
p t.strftime("%Y-%m") # => 2001-02 Calendar date, reduced accuracy, specific month
p t.strftime("%Y") # => 2001 Calendar date, reduced accuracy, specific year
p t.strftime("%C") # => 20 Calendar date, reduced accuracy, specific century
p t.strftime("%Y%j") # => 2001034 Ordinal date (basic)
p t.strftime("%Y-%j") # => 2001-034 Ordinal date (extended)
p t.strftime("%GW%V%u") # => 2001W056 Week date (basic)
p t.strftime("%G-W%V-%u") # => 2001-W05-6 Week date (extended)
p t.strftime("%GW%V") # => 2001W05 Week date, reduced accuracy, specific week (basic)
p t.strftime("%G-W%V") # => 2001-W05 Week date, reduced accuracy, specific week (extended)
p t.strftime("%H%M%S") # => 040506 Local time (basic)
p t.strftime("%T") # => 04:05:06 Local time (extended)
p t.strftime("%H%M") # => 0405 Local time, reduced accuracy, specific minute (basic)
p t.strftime("%H:%M") # => 04:05 Local time, reduced accuracy, specific minute (extended)
p t.strftime("%H") # => 04 Local time, reduced accuracy, specific hour
p t.strftime("%H%M%S,%L") # => 040506,000 Local time with decimal fraction, comma as decimal sign (basic)
p t.strftime("%T,%L") # => 04:05:06,000 Local time with decimal fraction, comma as decimal sign (extended)
p t.strftime("%H%M%S.%L") # => 040506.000 Local time with decimal fraction, full stop as decimal sign (basic)
p t.strftime("%T.%L") # => 04:05:06.000 Local time with decimal fraction, full stop as decimal sign (extended)
p t.strftime("%H%M%S%z") # => 040506+0900 Local time and the difference from UTC (basic)
p t.strftime("%T%:z") # => 04:05:06+09:00 Local time and the difference from UTC (extended)
p t.strftime("%Y%m%dT%H%M%S%z") # => 20010203T040506+0900 Date and time of day for calendar date (basic)
p t.strftime("%FT%T%:z") # => 2001-02-03T04:05:06+09:00 Date and time of day for calendar date (extended)
p t.strftime("%Y%jT%H%M%S%z") # => 2001034T040506+0900 Date and time of day for ordinal date (basic)
p t.strftime("%Y-%jT%T%:z") # => 2001-034T04:05:06+09:00 Date and time of day for ordinal date (extended)
p t.strftime("%GW%V%uT%H%M%S%z") # => 2001W056T040506+0900 Date and time of day for week date (basic)
p t.strftime("%G-W%V-%uT%T%:z") # => 2001-W05-6T04:05:06+09:00 Date and time of day for week date (extended)
p t.strftime("%Y%m%dT%H%M") # => 20010203T0405 Calendar date and local time (basic)
p t.strftime("%FT%R") # => 2001-02-03T04:05 Calendar date and local time (extended)
p t.strftime("%Y%jT%H%MZ") # => 2001034T0405Z Ordinal date and UTC of day (basic)
p t.strftime("%Y-%jT%RZ") # => 2001-034T04:05Z Ordinal date and UTC of day (extended)
p t.strftime("%GW%V%uT%H%M%z") # => 2001W056T0405+0900 Week date and local time and difference from UTC (basic)
p t.strftime("%G-W%V-%uT%R%:z") # => 2001-W05-6T04:05+09:00 Week date and local time and difference from UTC (extended)
subsec -> Integer | Rational
[permalink][rdoc]時刻を表す分数を返します。
Rational を返す場合があります。
t = Time.local(2000,1,2,3,4,5,6)
p "%10.9f" % t.to_f # => "946749845.000005960"
p t.subsec #=> (3/500000)
to_f の値と subsec の値の下のほうの桁の値は異なる場合があります。 というのは IEEE 754 double はそれを表すのに十分な精度を 持たないからです。subsec で得られる値が正確です。
succ -> Time
[permalink][rdoc]self に 1 秒足した Time オブジェクトを生成して返します。
このメソッドは obsolete です。 self + 1 を代わりに使用してください。
t = Time.local(2000)
p t # => 2000-01-01 00:00:00 +0900
p t.succ # => 2000-01-01 00:00:01 +0900
sunday? -> bool
[permalink][rdoc]self の表す時刻が日曜日である場合に true を返します。 そうでない場合に false を返します。
t = Time.local(1990, 4, 1) # => 1990-04-01 00:00:00 +0900
p t.sunday? # => true
thursday? -> bool
[permalink][rdoc]self の表す時刻が木曜日である場合に true を返します。 そうでない場合に false を返します。
t = Time.local(1995, 12, 21) # => 1995-12-21 00:00:00 +0900
p t.thursday? # => true
to_a -> Array
[permalink][rdoc]時刻を10要素の配列で返します。
その要素は順序も含めて以下の通りです。
t = Time.local(2000,1,2,3,4,5)
p t # => 2000-01-02 03:04:05 +0900
p t.to_a # => [5, 4, 3, 2, 1, 2000, 0, 2, false, "JST"]
要素の順序は C 言語の tm 構造体に合わせています。ただし、 tm 構造体に zone はありません。
注意: C 言語の tm 構造体とは異なり、month は 1 月に対 して 1 を返し、year は 1998 年に対して 1998 を返します。また、 yday は 1 から数えます。
to_f -> Float
[permalink][rdoc]起算時からの経過秒数を浮動小数点数で返します。1 秒に満たない経過も 表現されます。
t = Time.local(2000,1,2,3,4,5,6)
p t # => 2000-01-02 03:04:05 +0900
p "%10.6f" % t.to_f # => "946749845.000006"
p t.to_i # => 946749845
to_i -> Integer
[permalink][rdoc]tv_sec -> Integer
起算時からの経過秒数を整数で返します。
t = Time.local(2000,1,2,3,4,5,6)
p t # => 2000-01-02 03:04:05 +0900
p "%10.6f" % t.to_f # => "946749845.000006"
p t.to_i # => 946749845
p t.tv_sec # => 946749845
to_r -> Rational
[permalink][rdoc]起算時からの経過秒数を有理数で返します。1 秒に満たない経過も 表現されます。
t = Time.local(2000,1,2,3,4,5,6)
p t # => 2000-01-02 03:04:05 +0900
p t.to_r # => (473374922500003/500000)
to_s -> String
[permalink][rdoc]時刻を文字列に変換した結果を返します。 以下のようにフォーマット文字列を使って strftime を呼び出すのと同じです。
t = Time.local(2000,1,2,3,4,5,6)
p t.to_s # => "2000-01-02 03:04:05 +0900"
p t.strftime("%Y-%m-%d %H:%M:%S %z") # => "2000-01-02 03:04:05 +0900"
p t.utc.to_s # => "2000-01-01 18:04:05 UTC"
p t.strftime("%Y-%m-%d %H:%M:%S UTC") # => "2000-01-01 18:04:05 UTC"
戻り値の文字エンコーディングは Encoding::US_ASCII です。
tuesday? -> bool
[permalink][rdoc]self の表す時刻が火曜日である場合に true を返します。 そうでない場合に false を返します。
t = Time.local(1991, 2, 19) # => 1991-02-19 00:00:00 +0900
p t.tuesday? # => true
usec -> Integer
[permalink][rdoc]tv_usec -> Integer
時刻のマイクロ秒の部分を整数で返します。
t = Time.local(2000,1,2,3,4,5,6)
p "%10.6f" % t.to_f #=> "946749845.000006"
p t.usec #=> 6
wday -> Integer
[permalink][rdoc]曜日を0(日曜日)から6(土曜日)の整数で返します。
p sun = Time.new(2017, 9, 17, 10, 34, 15, '+09:00') # => 2017-09-17 10:34:15 +0900
p sun.wday # => 0
p mon = Time.new(2017, 9, 18, 10, 34, 15, '+09:00') # => 2017-09-18 10:34:15 +0900
p mon.wday # => 1
p tue = Time.new(2017, 9, 19, 10, 34, 15, '+09:00') # => 2017-09-19 10:34:15 +0900
p tue.wday # => 2
p wed = Time.new(2017, 9, 20, 10, 34, 15, '+09:00') # => 2017-09-20 10:34:15 +0900
p wed.wday # => 3
p thu = Time.new(2017, 9, 21, 10, 34, 15, '+09:00') # => 2017-09-21 10:34:15 +0900
p thu.wday # => 4
p fri = Time.new(2017, 9, 22, 10, 34, 15, '+09:00') # => 2017-09-22 10:34:15 +0900
p fri.wday # => 5
p sat = Time.new(2017, 9, 23, 10, 34, 15, '+09:00') # => 2017-09-23 10:34:15 +0900
p sat.wday # => 6
wednesday? -> bool
[permalink][rdoc]self の表す時刻が水曜日である場合に true を返します。 そうでない場合に false を返します。
t = Time.local(1993, 2, 24) # => 1993-02-24 00:00:00 +0900
p t.wednesday? # => true
yday -> Integer
[permalink][rdoc]1月1日を1とした通算日(1から366まで)を整数で返します。
p Time.mktime(2000, 1, 1).yday # => 1
うるう年の場合は、2月29日も含めた通算日を返します。
うるう年でない場合
p Time.mktime(2003, 1, 1).yday # => 1
p Time.mktime(2003, 3, 1).yday # => 60
p Time.mktime(2003, 12, 31).yday # => 365
うるう年の場合
p Time.mktime(2004, 1, 1).yday # => 1
p Time.mktime(2004, 2, 29).yday # => 60
p Time.mktime(2004, 12, 31).yday # => 366
year -> Integer
[permalink][rdoc]年を整数で返します。
t = Time.local(2000,1,2,3,4,5) # => 2000-01-02 03:04:05 +0900
p t.year # => 2000
zone -> String
[permalink][rdoc]タイムゾーンを表す文字列を返します。
p Time.now.zone # => "JST"