How can ruby determine if the DateTime object is within 24 hours?
I'd like to do time=time.zone.now
and then go see time
to determine if it's within 24 hours.
time=Time.zone.now
time>1.day.ago
In a Rails environment, you can write like this.
I think it will be easier to read colloquially.
http://railsdoc.com/references/ago
It looks like a Rails environment, so it's easy to use 1.day
.
(Time.zone.now-time)<1.day
true
if the time specified in is within 1 day (=24 hours).
Of course, 24.hours
can be used instead of 1.day
.
© 2024 OneMinuteCode. All rights reserved.