I have an array of Ruby Date objects. How can I find the newest datetime and the oldest datetime?
我有一组Ruby Date对象。如何找到最新的日期时间和最早的日期时间?
3 个解决方案
#1
24
date_array.min # => Oldest
date_array.max # => Most recent
#2
2
oldest, newest = date_array.minmax
#3
0
You have a comparison operator:
你有一个比较运算符:
http://www.ruby-doc.org/core/classes/Date.html#M000673
http://www.ruby-doc.org/core/classes/Date.html#M000673
Sort it.
把它分类。
#1
24
date_array.min # => Oldest
date_array.max # => Most recent
#2
2
oldest, newest = date_array.minmax
#3
0
You have a comparison operator:
你有一个比较运算符:
http://www.ruby-doc.org/core/classes/Date.html#M000673
http://www.ruby-doc.org/core/classes/Date.html#M000673
Sort it.
把它分类。