本文簡要介紹ruby語言中 Time.zone_offset
的用法。
用法
zone_offset(zone, year=self.now.year)
返回指定時區與 UTC 不同的秒數。
包括分鍾的 Numeric
時區(例如-10:00
或+1330
)將起作用,更簡單的hour-only 時區(例如-10
或+13
)也將起作用。
還支持ZoneOffset 中列出的文本時區。
如果時區與上述任何一項都不匹配,zone_offset
將檢查本地時區(無論是否存在潛在的夏令時更改)是否與 zone
匹配。指定 year
的值將更改用於查找本地時區的年份。
如果zone_offset
無法確定偏移量,則返回 nil。
require 'time'
Time.zone_offset("EST") #=> -18000
您必須要求 ‘time’ 才能使用此方法。
相關用法
- Ruby Time.zone用法及代碼示例
- 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.ceil用法及代碼示例
- Ruby Time.parse用法及代碼示例
- Ruby Time.thursday?用法及代碼示例
注:本文由純淨天空篩選整理自ruby-lang.org大神的英文原創作品 Time.zone_offset。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。