gpt4 book ai didi

ruby-on-rails - Rails 3/Ruby 1.9.2 Date.tomorrow 不正确

转载 作者:数据小太阳 更新时间:2023-10-29 06:51:53 25 4
gpt4 key购买 nike

在 Mac Snow leopard 上使用 Ruby 1.9.2 和 Rail 3

ruby-1.9.2-p290 :001 > Date.today
=> Sun, 25 Sep 2011
ruby-1.9.2-p290 :002 > Date.tomorrow
=> Tue, 27 Sep 2011

ruby 日期类是否有问题,或者这与我安装 ruby​​ 的方式有关吗?

编辑:

ruby-1.9.2-p290 :039 > Date.current
=> Mon, 26 Sep 2011
ruby-1.9.2-p290 :040 > DateTime.now
=> Sun, 25 Sep 2011 20:47:01 -0500

好吧,rails Date 类似乎有点问题。 DateTime 类似乎工作正常。感谢 derp 和 Adam

最佳答案

在网上查找资料,发现了这个:
https://rails.lighthouseapp.com/projects/8994/tickets/6410-dateyesterday-datetoday


检查最后一条评论:

I do agree with you that its a bit confusing that you need to use Date.current with Date.yesterday instead of Date.today, but the general rule of thumb is Rails does not change how Ruby methods work, which Date.today is. All we can do is add better documentation and make sure people are aware of the subtle difference.


换句话说,使用 current(rails) 而不是 today(ruby) 来避免问题。

关于ruby-on-rails - Rails 3/Ruby 1.9.2 Date.tomorrow 不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7549564/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com