给定3个数字:dd,mm,yyyy,如果它们结合了合法日期,最容易知道的方法是什么?
示例:
14, 05, 2011 => Legal
29, 02, 2011 => Illegal
29, 02, 2012 => Legal
35, 11, 1989 => Illegal
14, 18, 2011 => Illegal
14, 00, 2011 => Illegal
00, 11, 1979 => Illegal
31, 11, 1979 => Illegal
最佳答案
您可以使用valid_date?
,但它是YYYY, MM, DD
:
irb(main):015:0> require 'date'
=> true
irb(main):021:0> Date::valid_date?(2011,05,14)
=> true
irb(main):022:0> Date::valid_date?(2011,02,29)
=> false
irb(main):023:0> Date::valid_date?(2012,02,29)
=> true
关于ruby-on-rails - 如何确定给定的日期,月份和年份是否结合了法定日期?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5745666/