日期不能直接变成整数.前任:
$ Date.today
=> #<Date: 2017-12-29 ((2458117j,0s,0n),+0s,2299161j)>
$ Date.today.to_i
=> NoMethodError: undefined method 'to_i' for #<Date: 2017-12-29 ((2458117j,0s,0n),+0s,2299161j)>
您可以 Select 将日期转换为时间,然后再转换为整数,这将为您提供自纪元起的秒数:
$ Date.today.to_time.to_i
=> 1514523600
或者想出你想要的其他数字,比如从大纪元算起的天数:
$ Date.today.to_time.to_i / (60 * 60 * 24) ### Number of seconds in a day
=> 17529 ### Number of days since epoch