Active Support 附帶時區的時間
一個類似時間的類別,可以表示任何時區的時間。這是必要的,因為標準 Ruby Time
實例僅限於 UTC 和系統的 ENV['TZ']
時區。
您永遠不需要透過 new
直接建立 TimeWithZone
實例。相反的,請使用 TimeZone
實例上的 local
、parse
、at
和 now
方法,以及 Time
和 DateTime
實例上的 in_time_zone
方法。
Time.zone = 'Eastern Time (US & Canada)' # => 'Eastern Time (US & Canada)'
Time.zone.local(2007, 2, 10, 15, 30, 45) # => Sat, 10 Feb 2007 15:30:45.000000000 EST -05:00
Time.zone.parse('2007-02-10 15:30:45') # => Sat, 10 Feb 2007 15:30:45.000000000 EST -05:00
Time.zone.at(1171139445) # => Sat, 10 Feb 2007 15:30:45.000000000 EST -05:00
Time.zone.now # => Sun, 18 May 2008 13:07:55.754107581 EDT -04:00
Time.utc(2007, 2, 10, 20, 30, 45).in_time_zone # => Sat, 10 Feb 2007 15:30:45.000000000 EST -05:00
有關這些方法的更多說明,請參閱 Time
和 TimeZone
。
TimeWithZone
實例實現了與 Ruby Time
實例相同的 API,因此 Time
和 TimeWithZone
實例可以互換使用。
t = Time.zone.now # => Sun, 18 May 2008 13:27:25.031505668 EDT -04:00
t.hour # => 13
t.dst? # => true
t.utc_offset # => -14400
t.zone # => "EDT"
t.to_fs(:rfc822) # => "Sun, 18 May 2008 13:27:25 -0400"
t + 1.day # => Mon, 19 May 2008 13:27:25.031505668 EDT -04:00
t.beginning_of_year # => Tue, 01 Jan 2008 00:00:00.000000000 EST -05:00
t > Time.utc(1999) # => true
t.is_a?(Time) # => true
t.is_a?(ActiveSupport::TimeWithZone) # => true
- #
- A
- B
- C
- D
- E
- F
- G
- H
- I
- K
- L
- M
- N
- P
- R
- S
- T
- U
- X
- Y
- Z
常數
PRECISIONS | = | Hash.new { |h, n| h[n] = "%FT%T.%#{n}N" } |
SECONDS_PER_DAY | = | 86400 |
屬性
[R] | time_zone |
類別公開方法
new(utc_time, time_zone, local_time = nil, period = nil) 連結
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 51 def initialize(utc_time, time_zone, local_time = nil, period = nil) @utc = utc_time ? transfer_time_values_to_utc_constructor(utc_time) : nil @time_zone, @time = time_zone, local_time @period = @utc ? period : get_period_and_ensure_valid_local_time(period) end
實例公開方法
+(other) 連結
將時間間隔加到目前物件的時間,並將該值作為新的 TimeWithZone
物件傳回。
Time.zone = 'Eastern Time (US & Canada)' # => 'Eastern Time (US & Canada)'
now = Time.zone.now # => Sun, 02 Nov 2014 01:26:28.725182881 EDT -04:00
now + 1000 # => Sun, 02 Nov 2014 01:43:08.725182881 EDT -04:00
如果我們要添加一個可變長度的 Duration
(即年、月、日),則從 time
開始推進,否則為了在跨越 DST 邊界時保持準確性,從 utc
開始推進。
例如,時間 + 24.小時將精確推進 24 小時,而時間 + 1.天將推進 23-25 小時,具體取決於日期。
now + 24.hours # => Mon, 03 Nov 2014 00:26:28.725182881 EST -05:00
now + 1.day # => Mon, 03 Nov 2014 01:26:28.725182881 EST -05:00
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 298 def +(other) if duration_of_variable_length?(other) method_missing(:+, other) else begin result = utc + other rescue TypeError result = utc.to_datetime.since(other) ActiveSupport.deprecator.warn( "Adding an instance of #{other.class} to an instance of #{self.class} is deprecated. This behavior will raise " \ "a `TypeError` in Rails 8.1." ) result.in_time_zone(time_zone) end result.in_time_zone(time_zone) end end
-(other) 連結
減去時間間隔並傳回一個新的 TimeWithZone
物件,除非另一個值 acts_like?
time。在這種情況下,它將減去另一個時間,並以 Float
的形式傳回秒數差。
Time.zone = 'Eastern Time (US & Canada)' # => 'Eastern Time (US & Canada)'
now = Time.zone.now # => Mon, 03 Nov 2014 00:26:28.725182881 EST -05:00
now - 1000 # => Mon, 03 Nov 2014 00:09:48.725182881 EST -05:00
如果減去一個可變長度的 Duration
(即年、月、日),則從 time
開始後退,否則為了在跨越 DST 邊界時保持準確性,從 utc
開始後退。
例如,時間 - 24.小時將精確減去 24 小時,而時間 - 1.天將減去 23-25 小時,具體取決於日期。
now - 24.hours # => Sun, 02 Nov 2014 01:26:28.725182881 EDT -04:00
now - 1.day # => Sun, 02 Nov 2014 00:26:28.725182881 EDT -04:00
如果 TimeWithZone
物件和另一個值都像 Time
一樣,則會傳回 Float
。
Time.zone.now - 1.day.ago # => 86399.999967
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 341 def -(other) if other.acts_like?(:time) getutc - other.getutc elsif duration_of_variable_length?(other) method_missing(:-, other) else result = utc - other result.in_time_zone(time_zone) end end
<=>(other) 連結
使用 UTC 時間進行比較。
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 231 def <=>(other) utc <=> other end
acts_like_time?() 連結
以便 self
acts_like?(:time)
。
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 504 def acts_like_time? true end
advance(options) 連結
使用 Date
根據 proleptic Gregorian calendar 提供精確的 Time
年、月和日計算。結果將作為新的 TimeWithZone
物件傳回。
options
參數接受一個雜湊,其中包含以下任一鍵::years
、:months
、:weeks
、:days
、:hours
、:minutes
、:seconds
。
如果要推進可變長度的值(即年、週、月、日),則從 time
開始推進,否則為了在跨越 DST 邊界時保持準確性,從 utc
開始推進。
Time.zone = 'Eastern Time (US & Canada)' # => 'Eastern Time (US & Canada)'
now = Time.zone.now # => Sun, 02 Nov 2014 01:26:28.558049687 EDT -04:00
now.advance(seconds: 1) # => Sun, 02 Nov 2014 01:26:29.558049687 EDT -04:00
now.advance(minutes: 1) # => Sun, 02 Nov 2014 01:27:28.558049687 EDT -04:00
now.advance(hours: 1) # => Sun, 02 Nov 2014 01:26:28.558049687 EST -05:00
now.advance(days: 1) # => Mon, 03 Nov 2014 01:26:28.558049687 EST -05:00
now.advance(weeks: 1) # => Sun, 09 Nov 2014 01:26:28.558049687 EST -05:00
now.advance(months: 1) # => Tue, 02 Dec 2014 01:26:28.558049687 EST -05:00
now.advance(years: 1) # => Mon, 02 Nov 2015 01:26:28.558049687 EST -05:00
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 430 def advance(options) # If we're advancing a value of variable length (i.e., years, weeks, months, days), advance from #time, # otherwise advance from #utc, for accuracy when moving across DST boundaries if options.values_at(:years, :weeks, :months, :days).any? method_missing(:advance, options) else utc.advance(options).in_time_zone(time_zone) end end
ago(other) 連結
從目前物件的時間減去時間間隔,並將結果作為新的 TimeWithZone
物件傳回。
Time.zone = 'Eastern Time (US & Canada)' # => 'Eastern Time (US & Canada)'
now = Time.zone.now # => Mon, 03 Nov 2014 00:26:28.725182881 EST -05:00
now.ago(1000) # => Mon, 03 Nov 2014 00:09:48.725182881 EST -05:00
如果我們要減去一個可變長度的 Duration
(即年、月、日),則從 time
開始後退,否則為了在跨越 DST 邊界時保持準確性,從 utc
開始後退。
例如,time.ago(24.hours)
將精確後退 24 小時,而 time.ago(1.day)
將後退 23-25 小時,具體取決於日期。
now.ago(24.hours) # => Sun, 02 Nov 2014 01:26:28.725182881 EDT -04:00
now.ago(1.day) # => Sun, 02 Nov 2014 00:26:28.725182881 EDT -04:00
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 369 def ago(other) since(-other) end
as_json(options = nil) 連結
將時間強制轉換為字串,以便進行 JSON
編碼。預設格式為 ISO 8601。您可以透過將 ActiveSupport::JSON::Encoding.use_standard_json_time_format
設定為 false
來取得 %Y/%m/%d %H:%M:%S +offset 樣式。
# With ActiveSupport::JSON::Encoding.use_standard_json_time_format = true
Time.utc(2005,2,1,15,15,10).in_time_zone("Hawaii").as_json
# => "2005-02-01T05:15:10.000-10:00"
# With ActiveSupport::JSON::Encoding.use_standard_json_time_format = false
Time.utc(2005,2,1,15,15,10).in_time_zone("Hawaii").as_json
# => "2005/02/01 05:15:10 -1000"
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 166 def as_json(options = nil) if ActiveSupport::JSON::Encoding.use_standard_json_time_format xmlschema(ActiveSupport::JSON::Encoding.time_precision) else %(#{time.strftime("%Y/%m/%d %H:%M:%S")} #{formatted_offset(false)}) end end
between?(min, max) 連結
如果目前物件的時間在指定的 min
和 max
時間之內,則傳回 true。
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 239 def between?(min, max) utc.between?(min, max) end
blank?() 連結
ActiveSupport::TimeWithZone
的實例永遠不會是空白的
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 515 def blank? false end
change(options) 連結
傳回一個新的 ActiveSupport::TimeWithZone
,其中一個或多個元素已根據 options
參數進行更改。時間選項(:hour
、:min
、:sec
、:usec
、:nsec
)會依次重置,因此如果只傳遞小時,則分鐘、秒、微秒和奈秒會設定為 0。如果傳遞小時和分鐘,則秒、微秒和奈秒會設定為 0。options
參數接受一個雜湊,其中包含以下任一鍵::year
、:month
、:day
、:hour
、:min
、:sec
、:usec
、:nsec
、:offset
、:zone
。傳遞 :usec
或 :nsec
,而不是兩者都傳遞。同樣地,傳遞 :zone
或 :offset
,而不是兩者都傳遞。
t = Time.zone.now # => Fri, 14 Apr 2017 11:45:15.116992711 EST -05:00
t.change(year: 2020) # => Tue, 14 Apr 2020 11:45:15.116992711 EST -05:00
t.change(hour: 12) # => Fri, 14 Apr 2017 12:00:00.000000000 EST -05:00
t.change(min: 30) # => Fri, 14 Apr 2017 11:30:00.000000000 EST -05:00
t.change(offset: "-10:00") # => Fri, 14 Apr 2017 11:45:15.116992711 HST -10:00
t.change(zone: "Hawaii") # => Fri, 14 Apr 2017 11:45:15.116992711 HST -10:00
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 390 def change(options) if options[:zone] && options[:offset] raise ArgumentError, "Can't change both :offset and :zone at the same time: #{options.inspect}" end new_time = time.change(options) if options[:zone] new_zone = ::Time.find_zone(options[:zone]) elsif options[:offset] new_zone = ::Time.find_zone(new_time.utc_offset) end new_zone ||= time_zone periods = new_zone.periods_for_local(new_time) self.class.new(nil, new_zone, new_time, periods.include?(period) ? period : nil) end
dst?() 連結
如果目前時間在指定時區的日光節約時間內,則傳回 true。
Time.zone = 'Eastern Time (US & Canada)' # => 'Eastern Time (US & Canada)'
Time.zone.parse("2012-5-30").dst? # => true
Time.zone.parse("2012-11-30").dst? # => false
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 94 def dst? period.dst? end
eql?(other) 連結
如果 other
等於目前物件,則傳回 true
。
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 274 def eql?(other) other.eql?(utc) end
formatted_offset(colon = true, alternate_utc_string = nil) 連結
傳回格式化後的 UTC 時間偏移字串,如果時區已是 UTC,則傳回替代字串。
Time.zone = 'Eastern Time (US & Canada)' # => "Eastern Time (US & Canada)"
Time.zone.now.formatted_offset(true) # => "-05:00"
Time.zone.now.formatted_offset(false) # => "-0500"
Time.zone = 'UTC' # => "UTC"
Time.zone.now.formatted_offset(true, "0") # => "0"
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 125 def formatted_offset(colon = true, alternate_utc_string = nil) utc? && alternate_utc_string || TimeZone.seconds_to_utc_offset(utc_offset, colon) end
freeze() 連結
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 523 def freeze # preload instance variables before freezing period; utc; time; to_datetime; to_time super end
future?() 連結
如果目前的物件時間在未來,則傳回 true。
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 269 def future? utc.future? end
hash() 連結
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 278 def hash utc.hash end
httpdate() 連結
傳回以 HTTP 請求使用的格式表示物件日期和時間的字串。
Time.zone.now.httpdate # => "Tue, 01 Jan 2013 04:39:43 GMT"
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 186 def httpdate utc.httpdate end
in_time_zone(new_zone = ::Time.zone) 連結
傳回Time.zone
或指定時區的同步時間。
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 77 def in_time_zone(new_zone = ::Time.zone) return self if time_zone == new_zone utc.in_time_zone(new_zone) end
inspect() 連結
傳回物件的日期、時間、時區和 UTC 偏移量的字串。
Time.zone.now.inspect # => "Thu, 04 Dec 2014 11:00:25.624541392 EST -05:00"
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 140 def inspect "#{time.strftime('%F %H:%M:%S.%9N')} #{zone} #{formatted_offset}" end
is_a?(klass) 連結
將自身宣告為 Time
以避免類型檢查。
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 509 def is_a?(klass) klass == ::Time || super end
localtime(utc_offset = nil) 連結
傳回系統時區同步時間的 Time
實例。
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 83 def localtime(utc_offset = nil) utc.getlocal(utc_offset) end
marshal_dump() 連結
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 529 def marshal_dump [utc, time_zone.name, time] end
marshal_load(variables) 連結
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 533 def marshal_load(variables) initialize(variables[0].utc, ::Time.find_zone(variables[1]), variables[2].utc) end
method_missing(...) 連結
將遺漏的方法傳送至 time
實例,並將結果包裝在具有現有 time_zone
的新的 TimeWithZone
中。
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 553 def method_missing(...) wrap_with_time_zone time.__send__(...) rescue NoMethodError => e raise e, e.message.sub(time.inspect, inspect).sub("Time", "ActiveSupport::TimeWithZone"), e.backtrace end
past?() 連結
如果目前的物件時間在過去,則傳回 true。
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 244 def past? utc.past? end
period() 連結
傳回底層的 TZInfo::TimezonePeriod
。
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 72 def period @period ||= time_zone.period_for_utc(@utc) end
respond_to?(sym, include_priv = false) 連結
在某些情況下不會呼叫 respond_to_missing?,例如使用 Kernel#String 執行類型轉換時
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 539 def respond_to?(sym, include_priv = false) # ensure that we're not going to throw and rescue from NoMethodError in method_missing which is slow return false if sym.to_sym == :to_str super end
respond_to_missing?(sym, include_priv) 連結
確保代理類別回應底層時間實例回應的所有方法。
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 547 def respond_to_missing?(sym, include_priv) time.respond_to?(sym, include_priv) end
rfc2822() 連結
傳回以 RFC 2822 標準格式表示物件日期和時間的字串。
Time.zone.now.rfc2822 # => "Tue, 01 Jan 2013 04:51:39 +0000"
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 194 def rfc2822 to_fs(:rfc822) end
strftime(format) 連結
在傳遞至 Time#strftime 之前將 %Z
指令替換為 +zone,以便時區資訊正確無誤。
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 225 def strftime(format) format = format.gsub(/((?:\A|[^%])(?:%%)*)%Z/, "\\1#{zone}") getlocal(utc_offset).strftime(format) end
time() 連結
傳回表示 time_zone
時間的 Time
實例。
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 58 def time @time ||= incorporate_utc_offset(@utc, utc_offset) end
to_a() 連結
以 [秒、分鐘、小時、日、月、年、星期幾、一年中的第幾天、是否為日光節約時間、時區] 的順序傳回 陣列
的 時間
部分。
now = Time.zone.now # => Tue, 18 Aug 2015 02:29:27.485278555 UTC +00:00
now.to_a # => [27, 29, 2, 18, 8, 2015, 2, 230, false, "UTC"]
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 453 def to_a [time.sec, time.min, time.hour, time.day, time.mon, time.year, time.wday, time.yday, dst?, zone] end
to_datetime() 連結
傳回具有時區 UTC 偏移量的 DateTime
實例
Time.zone.now.to_datetime # => Tue, 18 Aug 2015 02:32:20 +0000
Time.current.in_time_zone('Hawaii').to_datetime # => Mon, 17 Aug 2015 16:32:20 -1000
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 486 def to_datetime @to_datetime ||= utc.to_datetime.new_offset(Rational(utc_offset, 86_400)) end
to_f() 連結
傳回物件的日期和時間,以自 Epoch(1970 年 1 月 1 日 00:00 UTC)以來的秒數的浮點數表示。
Time.zone.now.to_f # => 1417709320.285418
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 461 def to_f utc.to_f end
to_fs(format = :default) 連結
傳回物件日期和時間的字串
此方法是 to_formatted_s
的別名
接受一個可選的 format
參數
-
:default
- 預設值,模擬 Ruby Time#to_s 格式。 -
:db
- 格式以 UTC :db 時間輸出時間。請參閱Time#to_fs
(:db)。 -
可以使用
Time::DATE_FORMATS
中的任何鍵值。請參閱 active_support/core_ext/time/conversions.rb。
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 212 def to_fs(format = :default) if format == :db utc.to_fs(format) elsif formatter = ::Time::DATE_FORMATS[format] formatter.respond_to?(:call) ? formatter.call(self).to_s : strftime(formatter) else to_s end end
to_i() 連結
傳回物件的日期和時間,以自 Epoch(1970 年 1 月 1 日 00:00 UTC)以來的秒數的整數表示。
Time.zone.now.to_i # => 1417709320
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 469 def to_i utc.to_i end
to_r() 連結
將物件的日期和時間以自 Epoch(1970 年 1 月 1 日 00:00 UTC)以來的有理秒數返回。
Time.zone.now.to_r # => (708854548642709/500000)
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 478 def to_r utc.to_r end
to_s() 連結
傳回物件日期和時間的字串
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 200 def to_s "#{time.strftime("%Y-%m-%d %H:%M:%S")} #{formatted_offset(false, 'UTC')}" # mimicking Ruby Time#to_s format end
to_time() 連結
返回一個 Time
實例,根據 ActiveSupport.to_time_preserves_timezone
的設定,其時區與 self
相同、UTC 時間偏移量與 self
相同或使用本地系統時區。
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 493 def to_time if preserve_timezone == :zone @to_time_with_timezone ||= getlocal(time_zone) elsif preserve_timezone @to_time_with_instance_offset ||= getlocal(utc_offset) else @to_time_with_system_offset ||= getlocal end end
today?() 連結
如果目前物件的時間落在今天之內,則返回 true。
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 250 def today? time.today? end
tomorrow?() 連結
如果目前物件的時間落在下一天(明天)之內,則返回 true。
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 256 def tomorrow? time.tomorrow? end
utc() 連結
返回一個 UTC 時區中同時時間的 Time
實例。
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 63 def utc @utc ||= incorporate_utc_offset(@time, -utc_offset) end
utc?() 連結
如果目前的時區設定為 UTC,則返回 true。
Time.zone = 'UTC' # => 'UTC'
Time.zone.now.utc? # => true
Time.zone = 'Eastern Time (US & Canada)' # => 'Eastern Time (US & Canada)'
Time.zone.now.utc? # => false
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 105 def utc? zone == "UTC" || zone == "UCT" end
utc_offset() 連結
返回目前時間到 UTC 時間的偏移量(以秒為單位)。
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 111 def utc_offset period.observed_utc_offset end
xmlschema(fraction_digits = 0) 連結
以 ISO 8601 標準格式返回物件的日期和時間字串。
Time.zone.now.xmlschema # => "2014-12-04T11:02:37-05:00"
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 148 def xmlschema(fraction_digits = 0) "#{time.strftime(PRECISIONS[fraction_digits.to_i])}#{formatted_offset(true, 'Z')}" end
yesterday?() 連結
如果目前物件的時間落在前一天(昨天)之內,則返回 true。
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 263 def yesterday? time.yesterday? end
zone() 連結
返回時區縮寫。
Time.zone = 'Eastern Time (US & Canada)' # => "Eastern Time (US & Canada)"
Time.zone.now.zone # => "EST"
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/time_with_zone.rb, line 133 def zone period.abbreviation end