5件ヒット
[1-5件を表示]
(0.019秒)
検索結果
先頭5件
-
Time
. strptime(date , format , now=self . now) -> Time (82363.0) -
文字列を Date._strptime を用いて Time オブジェクト に変換します。
...time を用いて 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.strptime......end
}
#=> 1991-05-18 04:13:00 +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... -
Time
. strptime(date , format , now=self . now) {|y| . . . } -> Time (82363.0) -
文字列を Date._strptime を用いて Time オブジェクト に変換します。
...time を用いて 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.strptime......end
}
#=> 1991-05-18 04:13:00 +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... -
Time
. parse(date , now = Time . now) -> Time (64735.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 (64735.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より前は例外は発生せず... -
Timeout
. # timeout(sec , exception _ class = nil) {|i| . . . } -> object (27376.0) -
ブロックを sec 秒の期限付きで実行します。 ブロックの実行時間が制限を過ぎたときは例外 Timeout::Error が発生します。
...sec 秒の期限付きで実行します。
ブロックの実行時間が制限を過ぎたときは例外
Timeout::Error が発生します。
exception_class を指定した場合には Timeout::Error の代わりに
その例外が発生します。
ブロックパラメータ i は sec がは......アウト
require 'timeout'
def calc_pi(min)
loop do
x = rand
y = rand
x**2 + y**2 < 1.0 ? min[0] += 1 : min[1] += 1
end
end
t = 5
min = [ 0, 0]
begin
Timeout.timeout(t){
calc_pi(min)
}
rescue Timeout::Error
puts "timeout"
end
printf......るタイムアウト
#!/usr/bin/env ruby
require 'timeout'
class MYError < Exception;end
begin
Timeout.timeout(5, MYError) {
sleep(30)
}
rescue MYError => err
puts "MYError"
puts err
end
=== 注意
timeout による割り込みは Thread によって実現さ...