Ruby 1.8.7 リファレンスマニュアル > ライブラリ一覧 > 組み込みライブラリ > Timeクラス
クラスの継承リスト: Time < Comparable < Object < Kernel
時刻を表すクラスです。
Time.now は現在の時刻を返します。 File.mtime などが返すファイルのタイムスタンプは Time オブジェクトです。
Time オブジェクトは時刻を起算時からの経過秒数で保持しています。 起算時は協定世界時(UTC、もしくはその旧称から GMT とも表記されます) の 1970年1月1日午前0時です。なお、うるう秒を勘定するかどうかはシステムに よります。
現在の Unix システムでの最大時刻は、 協定世界時の2038年1月19日午前3時14分7秒 です。
Time オブジェクトが格納可能な時刻の範囲は環境によって異なります。 範囲の下限としては、上記起算時からの経過秒数として 0 および正数しか 受け付けない環境もあれば、負数も受け付ける環境もあります。 また、範囲の上限としては、上記の Unix システムでの最大時刻を越えて 64bit 値の範囲の経過秒数を受け付ける環境もあります。 さらに、他に特定の時点を越える時刻の値を受け付けない環境もあります。 Time オブジェクトを生成する各メソッドで、それぞれの環境での範囲外の 時刻を格納しようとした場合は例外が発生します。
また、Time オブジェクトは協定世界時と地方時のどちらのタイムゾー ンを使用するかのフラグを内部に保持しています。 ただし、この情報は Marshal.#dump では保存されず、Marshal.#load で読み込んだ Time オブジェクトのタイムゾーンは常に地方時になりま す。
p Marshal.load(Marshal.dump(Time.now.gmtime)).zone # => "JST"
time ライブラリによって、Time.parse, Time.rfc2822, Time.httpdate, Time.iso8601 等が拡張されます。
localtime(3) も参照しください。
C 言語の tm 構造体とは異なり、month は 1 月に対 して 1 を返し、year は 1998 年に対して 1998 を返します。また、 yday は 1 から数えます。
定義 | 説明 | |
---|---|---|
at(time) -> Time
|
time で指定した時刻の Time オブジェクトを返します。 |
|
at(time, usec) -> Time
|
time + (usec/1000000) の時刻を表す Time オブジェクトを返します。 浮動小数点の精度では不十分な場合に使用します。 |
|
gm(year, mon = 1, day = 1, hour = 0, min = 0, sec = 0, usec = 0) -> Time
|
引数で指定した協定世界時の Time オブジェクトを返します。 |
|
gm(sec, min, hour, mday, mon, year, wday, yday, isdst, zone) -> Time
|
引数で指定した協定世界時の Time オブジェクトを返します。 |
|
local(year, mon = 1, day = 1, hour = 0, min = 0, sec = 0, usec = 0) -> Time
|
引数で指定した地方時の Time オブジェクトを返します。 |
|
local(sec, min, hour, mday, mon, year, wday, yday, isdst, zone) -> Time
|
引数で指定した地方時の Time オブジェクトを返します。 |
|
new -> Time
|
現在時刻の Time オブジェクトを生成して返します。 タイムゾーンは地方時となります。 |
|
times -> Struct::Tms
|
このメソッドは obsolete です。 |
定義 | 説明 | |
---|---|---|
self + other -> Time
|
self より other 秒だけ後の時刻を返します。 |
|
self - time -> Float
|
自身と time との時刻の差を Float で返します。単位は秒です。 |
|
self - sec -> Time
|
自身より sec 秒だけ前の時刻を返します。 |
|
self <=> other -> -1 | 0 | 1 | nil
|
self と other の時刻を比較します。self の方が大きい場合は 1 を、等しい場合は 0 を、 小さい場合は -1 を返します。比較できない場合は、nil を返します。 |
|
asctime -> String
|
時刻を asctime(3) の形式の文字列に変換します。た だし、末尾の改行文字 "\n" は含まれません。 |
|
mday -> Integer
|
日を整数で返します。 |
|
isdst -> bool
|
自身が表す日時が夏時間なら true を返します。そうでないなら false を返します。 |
|
eql?(other) -> bool
|
other が Time かそのサブクラスのインスタンスであり自身と時刻が等しい場合に true を返します。そうでない場合に false を返します。 |
|
getgm -> Time
|
タイムゾーンを協定世界時に設定した Time オブジェクトを新しく 生成して返します。 |
|
getlocal -> Time
|
タイムゾーンを地方時に設定した Time オブジェクトを新しく生成 して返します。 |
|
gmt? -> bool
|
self のタイムゾーンが協定世界時に設定されていれば真を返します。 |
|
utc_offset -> Integer
|
協定世界時との時差を秒を単位とする数値として返します。 |
|
gmtime -> self
|
タイムゾーンを協定世界時に設定します。 |
|
hour -> Integer
|
時を整数で返します。 |
|
localtime -> self
|
タイムゾーンを地方時に設定します。 |
|
min -> Integer
|
分を整数で返します。 |
|
mon -> Integer
|
月を整数で返します。 |
|
sec -> Integer
|
秒を整数で返します。 |
|
strftime(format) -> String
|
時刻を format 文字列に従って文字列に変換した結果を返します。 |
|
succ -> Time
|
self に 1 秒足した Time オブジェクトを生成して返します。 |
|
to_a -> Array
|
時刻を10要素の配列で返します。その要素は順序も含めて以下の通りです。 |
|
to_f -> Float
|
起算時からの経過秒数を浮動小数点数で返します。1 秒に満たない経過も 表現されます。 |
|
to_i -> Integer
|
起算時からの経過秒数を整数で返します。 |
|
to_s -> String
|
時刻を date(1) のような形式の文字列に変換します。 |
|
usec -> Integer
|
時刻のマイクロ秒の部分を整数で返します。 |
|
wday -> Integer
|
曜日を0(日曜日)から6(土曜日)の整数で返します。 |
|
yday -> Integer
|
1月1日を1とした通算日(1から366まで)を整数で返します。 |
|
year -> Integer
|
年を整数で返します。 |
|
zone -> String
|
タイムゾーンを表す文字列を返します。 |
<
<=
==
>
>=
between?
===
=~
__id__
__send__
_dump
class
clone
dclone
display
enum_for
equal?
extend
freeze
frozen?
hash
initialize
initialize_copy
inspect
instance_eval
instance_exec
instance_of?
instance_variable_defined?
instance_variable_get
instance_variable_set
instance_variables
is_a?
marshal_dump
marshal_load
method
method_missing
methods
nil?
pretty_inspect
pretty_print
pretty_print_cycle
pretty_print_inspect
pretty_print_instance_variables
private_methods
protected_methods
public_methods
remove_instance_variable
respond_to?
singleton_method_added
singleton_method_removed
singleton_method_undefined
singleton_methods
taint
tainted?
tap
to_ary
to_hash
to_int
to_io
to_proc
to_regexp
to_str
to_yaml
to_yaml_properties
to_yaml_style
untaint
定義 | 説明 | ライブラリ |
---|---|---|
httpdate(date) -> Time
|
time | |
httpdate -> String
|
[RFC2616]で定義されているHTTP-dateのrfc1123-dateとして 表現される以下の形式の文字列を返します: |
time |
xmlschema(date) -> Time
|
XML Schema で定義されている dateTime として date をパースして Time オブジェクトに変換します。 |
time |
xmlschema(fractional_seconds = 0) -> String
|
XML Schema で定義されている dateTime として 表現される以下の形式の文字列を返します: |
time |
parse(date, now = Time.now) -> Time
|
date を ParseDate.#parsedate によって パースして Timeオブジェクトに変換します。 |
time |
rfc2822 -> String
|
[RFC2822] で定義されている date-time として表現される 以下の形式の文字列を返します: |
time |
rfc2822(date) -> Time
|
[RFC2822]で定義されているdate-timeとしてdateをパースして Timeオブジェクトに変換します。 この形式は[RFC822]で定義されて[RFC1123]で更新された形式と 同じです。 |
time |