gpt4 book ai didi

ruby-on-rails - 检查 DateTime 值是今天、明天还是之后

转载 作者:行者123 更新时间:2023-12-03 09:01:42 25 4
gpt4 key购买 nike

我有一个 DateTime 类的对象属性。

我如何理解保存的日期是今天、明天还是更晚?

最佳答案

以下是一些有用的方法来实现它:

datetime = DateTime.now  => Sun, 26 Oct 2014 21:00:00

datetime.today? # => true
datetime.to_date.past? # => false (only based on date)
datetime.to_date.future? # => false (only based on date)

datetime.to_date == Date.tomorrow # => false
datetime.to_date == Date.yesterday # => false

关于ruby-on-rails - 检查 DateTime 值是今天、明天还是之后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26578553/

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