本文簡要介紹ruby語言中 Time.getlocal
的用法。
用法
getlocal → new_time
getlocal(utc_offset) → new_time
getlocal(timezone) → new_time
返回一個新的 Time
對象,以本地時間表示 time
(使用對此過程有效的本地時區)。
如果給出utc_offset
,則使用它而不是本地時間。 utc_offset
可以作為人類可讀的字符串(例如 "+09:00"
)或秒數(例如 32400
)給出。
t = Time.utc(2000,1,1,20,15,1) #=> 2000-01-01 20:15:01 UTC
t.utc? #=> true
l = t.getlocal #=> 2000-01-01 14:15:01 -0600
l.utc? #=> false
t == l #=> true
j = t.getlocal("+09:00") #=> 2000-01-02 05:15:01 +0900
j.utc? #=> false
t == j #=> true
k = t.getlocal(9*60*60) #=> 2000-01-02 05:15:01 +0900
k.utc? #=> false
t == k #=> true
相關用法
- Ruby Time.getutc用法及代碼示例
- Ruby Time.getgm用法及代碼示例
- Ruby Time.gmtime用法及代碼示例
- Ruby Time.gmt?用法及代碼示例
- Ruby Time.gmt_offset用法及代碼示例
- Ruby Time.gmtoff用法及代碼示例
- 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.round用法及代碼示例
- Ruby Time.dst?用法及代碼示例
- Ruby Time.tv_nsec用法及代碼示例
- Ruby Time.xmlschema用法及代碼示例
- Ruby Time.to_r用法及代碼示例
- Ruby Time.ceil用法及代碼示例
- Ruby Time.parse用法及代碼示例
注:本文由純淨天空篩選整理自ruby-lang.org大神的英文原創作品 Time.getlocal。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。