在Python中,如果我想检查特定日期+ 24小时过去了,我会写:
from datetime import datetime, timedelta
some_date = datetime(2013, 1, 10, 11, 0)
day = timedelta(1)
# Checks if some_date + 1 day is before today's date
print some_date + day < datetime.now()
如何构建1天的时差并检查特定日期+ 1天是否在今天的Ruby日期之前?
答案 0 :(得分:2)
require 'time'
xmas = DateTime.new(2013, 12, 25)
puts x = xmas + 1 # 2013-12-26T00:00:00+00:00
d = DateTime.now
puts x > d # true
puts x - d # 30167183979194791/86400000000000 (a Rational)
puts d >> 12 # 2014-01-10T21:15:20+01:00