Ruby on Rails:比较两个日期的最佳方式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4356269/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 23:48:33 来源:igfitidea点击:
Ruby on Rails: the best way to compare two dates?
提问by krn
I have a date variable, stored as a String in the 'YYYY-mm-dd' format. What is the best way to check, if that date has not already passed?
我有一个日期变量,以“YYYY-mm-dd”格式存储为字符串。如果该日期尚未过去,最好的检查方法是什么?
回答by David Sulc
Date.parse('2010-11-01') < Date.today
will return true if '2010-11-01' has already passed
如果 '2010-11-01' 已经过去,则返回 true
回答by danivalentin
You can also use past?
你也可以用过去?
Date.parse("2012-11-01").past?

