开发者

What is the difference between Date.current and Date.today?

T开发者_开发问答hey both seem to do the same thing. I'm just worried that one uses timezones differently to the other.


See Rails code, line 40 here.

# Returns Time.zone.today when <tt>Time.zone</tt> or <tt>config.time_zone</tt> are     set, otherwise just returns Date.today.
  def current
    ::Time.zone ? ::Time.zone.today : ::Date.today
  end

So If you defined a timezone, you'll get a zoned Date otherwise you'll get Date.today.

BTW there is no Date.now


If you're doing comparisons you should always use Date.current

This is because if you're in a timezone that could be in a different day than UTC, and your timezone isn't set then you can have the situation where Date.today == Date.tomorrow

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜