本文簡要介紹ruby語言中 Time.ceil
的用法。
用法
ceil([ndigits]) → new_time
Ceils 亞秒到十進製數字的給定精度(默認為 0 位)。它返回一個新的 Time
對象。 ndigits
應為零或正整數。
t = Time.utc(2010,3,30, 5,43,25.0123456789r)
t #=> 2010-03-30 05:43:25 123456789/10000000000 UTC
t.ceil #=> 2010-03-30 05:43:26 UTC
t.ceil(0) #=> 2010-03-30 05:43:26 UTC
t.ceil(1) #=> 2010-03-30 05:43:25.1 UTC
t.ceil(2) #=> 2010-03-30 05:43:25.02 UTC
t.ceil(3) #=> 2010-03-30 05:43:25.013 UTC
t.ceil(4) #=> 2010-03-30 05:43:25.0124 UTC
t = Time.utc(1999,12,31, 23,59,59)
(t + 0.4).ceil #=> 2000-01-01 00:00:00 UTC
(t + 0.9).ceil #=> 2000-01-01 00:00:00 UTC
(t + 1.4).ceil #=> 2000-01-01 00:00:01 UTC
(t + 1.9).ceil #=> 2000-01-01 00:00:01 UTC
t = Time.utc(1999,12,31, 23,59,59)
(t + 0.123456789).ceil(4) #=> 1999-12-31 23:59:59.1235 UTC
相關用法
- Ruby Time.ctime用法及代碼示例
- Ruby Time.gmtime用法及代碼示例
- Ruby Time.at用法及代碼示例
- Ruby Time.utc_offset用法及代碼示例
- Ruby Time.isdst用法及代碼示例
- Ruby Time.time + numeric用法及代碼示例
- Ruby Time.wednesday?用法及代碼示例
- Ruby Time.localtime用法及代碼示例
- Ruby Time.yday用法及代碼示例
- Ruby Time.time <=>用法及代碼示例
- Ruby Time.month用法及代碼示例
- Ruby Time.utc?用法及代碼示例
- Ruby Time.new用法及代碼示例
- Ruby Time.monday?用法及代碼示例
- Ruby Time.getutc用法及代碼示例
- Ruby Time.round用法及代碼示例
- Ruby Time.dst?用法及代碼示例
- Ruby Time.tv_nsec用法及代碼示例
- Ruby Time.xmlschema用法及代碼示例
- Ruby Time.gmt?用法及代碼示例
- Ruby Time.to_r用法及代碼示例
- Ruby Time.gmt_offset用法及代碼示例
- Ruby Time.parse用法及代碼示例
- Ruby Time.thursday?用法及代碼示例
- Ruby Time.floor用法及代碼示例
注:本文由純淨天空篩選整理自ruby-lang.org大神的英文原創作品 Time.ceil。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。