Ruby 1.9.2 リファレンスマニュアル > ライブラリ一覧 > 組み込みライブラリ > Timeクラス
クラスの継承リスト: Time < Comparable < Object < Kernel < BasicObject
時刻を表すクラスです。
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 データに保持されます。
p Marshal.load(Marshal.dump(Time.now.gmtime)).zone # => "UTC"
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 オブジェクトを生成して返します。 タイムゾーンは地方時となります。 |
定義 | 説明 | |
---|---|---|
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 を返します。 |
|
friday? -> bool
|
自身の表す時刻が金曜日である場合に true を返します。 そうでない場合に false を返します。 |
|
getgm -> Time
|
タイムゾーンを協定世界時に設定した Time オブジェクトを新しく 生成して返します。 |
|
getlocal -> Time
|
タイムゾーンを地方時に設定した Time オブジェクトを新しく生成 して返します。 |
|
gmt? -> bool
|
self のタイムゾーンが協定世界時に設定されていれば真を返します。 |
|
utc_offset -> Integer
|
協定世界時との時差を秒を単位とする数値として返します。 |
|
gmtime -> self
|
タイムゾーンを協定世界時に設定します。 |
|
hour -> Integer
|
時を整数で返します。 |
|
localtime -> self
|
タイムゾーンを地方時に設定します。 |
|
min -> Integer
|
分を整数で返します。 |
|
mon -> Integer
|
月を整数で返します。 |
|
monday? -> bool
|
自身の表す時刻が月曜日である場合に true を返します。 そうでない場合に false を返します。 |
|
nsec -> Integer
|
時刻のナノ秒の部分を整数で返します。 |
|
round(ndigits=0) -> Time
|
Rounds sub seconds to a given precision in decimal digits (0 digits by default). It returns a new time object. _ndigits_ should be zero or positive integer. |
|
saturday? -> bool
|
自身の表す時刻が土曜日である場合に true を返します。 そうでない場合に false を返します。 |
|
sec -> Integer
|
秒を整数で返します。 |
|
strftime(format) -> String
|
時刻を format 文字列に従って文字列に変換した結果を返します。 |
|
subsec -> number
|
Returns just the fraction for <i>time</i>. |
|
succ -> Time
|
self に 1 秒足した Time オブジェクトを生成して返します。 |
|
sunday? -> bool
|
自身の表す時刻が日曜日である場合に true を返します。 そうでない場合に false を返します。 |
|
thursday? -> bool
|
自身の表す時刻が木曜日である場合に true を返します。 そうでない場合に false を返します。 |
|
to_a -> Array
|
時刻を10要素の配列で返します。その要素は順序も含めて以下の通りです。 |
|
to_f -> Float
|
起算時からの経過秒数を浮動小数点数で返します。1 秒に満たない経過も 表現されます。 |
|
to_i -> Integer
|
起算時からの経過秒数を整数で返します。 |
|
to_r -> Rational
|
Returns the value of <i>time</i> as a rational number of seconds since the Epoch. |
|
to_s -> String
|
時刻を date(1) のような形式の文字列に変換します。 |
|
tuesday? -> bool
|
自身の表す時刻が火曜日である場合に true を返します。 そうでない場合に false を返します。 |
|
usec -> Integer
|
時刻のマイクロ秒の部分を整数で返します。 |
|
wday -> Integer
|
曜日を0(日曜日)から6(土曜日)の整数で返します。 |
|
wednesday? -> bool
|
自身の表す時刻が水曜日である場合に true を返します。 そうでない場合に false を返します。 |
|
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
must_be
must_be_close_to
must_be_empty
must_be_instance_of
must_be_kind_of
must_be_nil
must_be_same_as
must_be_within_epsilon
must_equal
must_include
must_match
must_raise
must_respond_to
must_send
must_throw
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?
respond_to_missing?
singleton_class
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
trust
untaint
untrust
untrusted?
wont_be
wont_be_close_to
wont_be_empty
wont_be_instance_of
wont_be_kind_of
wont_be_nil
wont_be_same_as
wont_be_within_epsilon
wont_equal
wont_include
wont_match
wont_respond_to