るりまサーチ

最速Rubyリファレンスマニュアル検索!
956件ヒット [1-100件を表示] (0.062秒)
トップページ > クエリ:p[x] > クラス:Time[x]

別のキーワード

  1. openssl p
  2. openssl p=
  3. fileutils mkdir_p
  4. dh p
  5. rsa p

ライブラリ

キーワード

検索結果

<< 1 2 3 ... > >>

Time#httpdate -> String (6107.0)

2616 で定義されている HTTP-date の rfc1123-date 形式の文字列を 返します。

...いる HTTP-date の rfc1123-date 形式の文字列を
返します。

@return 以下の形式の文字列を返します。
//emlist{
day-of-week, DD month-name CCYY hh:mm:ss GMT
//}
注意: 結果はいつも UTC (GMT) です。

使用例
require 'time'

iso8601_time = '2008-08-31...
...T12:34:56+09:00'
t = Time.iso8601(iso8601_time)
p
t.httpdate #=> "Sun, 31 Aug 2008 03:34:56 GMT"...

Time.httpdate(date) -> Time (6107.0)

2616で定義されているHTTP-dateとしてdateをパースして Timeオブジェクトに変換します。

...いるHTTP-dateとしてdateをパースして
Time
オブジェクトに変換します。

dateが2616に準拠していない、または
Time
クラスが指定された日時を表現できないときにArgumentErrorが
発生します。

@param date 2616で定義されているHTTP-dateとし...
... Timeクラスが指定された日時を表現できないときに発生します。

require 'time'
rfc2616_time = 'Sun, 31 Aug 2008 12:34:56 GMT'

t = Time.httpdate(rfc2616_time)
p
t.kind_of?(Time) #=> true

non_rfc2616_time = 'San, 31 Aug 2008 12:34:56 GMT'
begin
Time
.httpdat...
...e(non_rfc2616_time)
rescue ArgumentError => err
p
uts err #=> not RFC 2616 compliant date: "San, 31 Aug 2008 12:34:56 GMT"
end...

Time#inspect -> String (6101.0)

時刻を文字列に変換した結果を返します。

...返します。

Time
#to_s とは異なりナノ秒まで含めて返します。

//emlist[][ruby]{
t = Time.now
t.inspect #=> "2012-11-10 18:16:12.261257655 +0100"
t.strftime "%Y-%m-%d %H:%M:%S.%N %z" #=> "2012-11-10 18:16:12.261257655 +0100"

t.utc.inspect...
...#=> "2012-11-10 17:16:12.261257655 UTC"
t.strftime "%Y-%m-%d %H:%M:%S.%N UTC" #=> "2012-11-10 17:16:12.261257655 UTC"
//}

戻り値の文字エンコーディングは Encoding::US_ASCII です。...

Time.parse(date, now = Time.now) -> Time (6101.0)

...date を Date._parse によって
パースして Timeオブジェクトに変換します。

ブロック付きで呼ばれた場合、dateの年はブロックによって変換されます。

require 'time'
Time
.parse(...) {|y| y < 100 ? (y >= 69 ? y + 1900 : y + 2000) : y}

与えられ...
...require 'time'
time
= Time.local(2019, 5, 1)
Time
.parse("12:00", time) #=> 2019-05-01 12:00:00 +0900

下位の要素がなかったり壊れていた場合、最小値(1か0)が使われます。

@param date Time オブジェクトに変換可能な文字列を指定します。
@param now...
...現在時刻をTime オブジェクトで指定します。
デフォルトはTime.nowとなります。

@raise ArgumentError dateに空文字列を与えた場合、発生します。
なお、1.9.2より前は例外は発生せず、現在時刻を表す...

Time.parse(date, now = Time.now) {|year| year } -> Time (6101.0)

...date を Date._parse によって
パースして Timeオブジェクトに変換します。

ブロック付きで呼ばれた場合、dateの年はブロックによって変換されます。

require 'time'
Time
.parse(...) {|y| y < 100 ? (y >= 69 ? y + 1900 : y + 2000) : y}

与えられ...
...require 'time'
time
= Time.local(2019, 5, 1)
Time
.parse("12:00", time) #=> 2019-05-01 12:00:00 +0900

下位の要素がなかったり壊れていた場合、最小値(1か0)が使われます。

@param date Time オブジェクトに変換可能な文字列を指定します。
@param now...
...現在時刻をTime オブジェクトで指定します。
デフォルトはTime.nowとなります。

@raise ArgumentError dateに空文字列を与えた場合、発生します。
なお、1.9.2より前は例外は発生せず、現在時刻を表す...

絞り込み条件を変える

Time.strptime(date, format, now=self.now) -> Time (6101.0)

文字列を Date._strptime を用いて Time オブジェクト に変換します。

...trptime を用いて Time オブジェクト
に変換します。

require 'time'
Time
.strptime('2001-02-03T04:05:06+09:00', '%Y-%m-%dT%H:%M:%S%z')
#=> 2001-02-03 06:05:06 +0900

ブロックを渡すと年の部分をブロックによって変換できます。
require 'time'
Time
.strpt...
...+0900

Time
.strptime('01/5/18 4:13:00', '%Y/%m/%d %T'){|y|
if y > 100 then y
elsif y >= 69 then y + 1900
else y + 2000
end
}
#=> 2001-05-18 04:13:00 +0900

詳しくは DateTime.strptime, Date.strptime を見てください。

@param date 時刻を表す文字列
@param f...

Time.strptime(date, format, now=self.now) {|y| ... } -> Time (6101.0)

文字列を Date._strptime を用いて Time オブジェクト に変換します。

...trptime を用いて Time オブジェクト
に変換します。

require 'time'
Time
.strptime('2001-02-03T04:05:06+09:00', '%Y-%m-%dT%H:%M:%S%z')
#=> 2001-02-03 06:05:06 +0900

ブロックを渡すと年の部分をブロックによって変換できます。
require 'time'
Time
.strpt...
...+0900

Time
.strptime('01/5/18 4:13:00', '%Y/%m/%d %T'){|y|
if y > 100 then y
elsif y >= 69 then y + 1900
else y + 2000
end
}
#=> 2001-05-18 04:13:00 +0900

詳しくは DateTime.strptime, Date.strptime を見てください。

@param date 時刻を表す文字列
@param f...

Time#strftime(format) -> String (265.0)

時刻を format 文字列に従って文字列に変換した結果を返します。

...時刻を format 文字列に従って文字列に変換した結果を返します。

@param format フォーマット文字列を指定します。使用できるものは 以下の通りです。

* %A: 曜日の名称(Sunday, Monday ... )
* %a: 曜日の省略名(Sun, Mon ... )
* %B: 月...
...%P: 午前または午後(am,pm)
* %p: 午前または午後(AM,PM)
* %Q: 1970-01-01 00:00:00 UTC からの経過ミリ秒 (Time#strftime は対応していませんが、Date#strftime で使えます)
* %R: 24時間制の時刻。%H:%M と同等。
* %r: 12時間制の時刻。%I:%M:%S %p...
...セット (例 +09:00:00)
* %%: %自身
* %+: date(1)の形式 (%a %b %e %H:%M:%S %Z %Y) (Time#strftime は対応していませんが、Date#strftime で使えます)

このメソッドは strftime(3) や glibcの仕様を参考に作成されており、以下のオプションが利用でき...

Time#wday -> Integer (85.0)

曜日を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....
...5 +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.wd...
...# => 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...
<< 1 2 3 ... > >>