Date.current 和 Date.today 有什么区别? [英] What is the difference between Date.current and Date.today?

查看:73
本文介绍了Date.current 和 Date.today 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

他们似乎都在做同样的事情.我只是担心一个人使用的时区与另一个不同.

They both seem to do the same thing. I'm just worried that one uses timezones differently to the other.

推荐答案

参见 Rails 代码,第 40 行 这里.

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

所以如果你定义了一个时区,你会得到一个分区日期,否则你会得到Date.today.

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

顺便说一句,没有Date.now

这篇关于Date.current 和 Date.today 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆