Is Time.zone.now.to_date equivalent to Date.today?

前端 未结 4 1458
栀梦
栀梦 2020-12-28 12:47

Is Time.zone.now.to_date equivalent to Date.today?

Another way to put it: will Time.zone.now.to_date == Date.today always be <

4条回答
  •  萌比男神i
    2020-12-28 13:19

    I think the best way is to learn the current time through:

    Time.current
    

    This will automatically check to see if you have timezone set then it will call Time.zone.now, but if you've not it will call just Time.now.

    Also, don't forget to set your timezone in application.rb

提交回复
热议问题