Compare two times without regard to Date associated - Ruby
Posted
by
H55nick
on Stack Overflow
See other posts from Stack Overflow
or by H55nick
Published on 2013-06-26T21:59:56Z
Indexed on
2013/06/26
22:21 UTC
Read the original article
Hit count: 175
I am trying to find the difference in time (without days/years/months) of two different days.
Example:
#ruby >1.9
time1 = Time.now - 1.day
time2 = Time.now
#code to make changes
#test:
time1 == time2 # TRUE
My solution:
time1 = time1.strftime("%h:%m").to_time
time2 = time2.strftime("%h:%m").to_time
#test
time1 == time2 #True
#passes
I was wondering if there was a better way of doing this? Maybe we could keep the Date the same as time1/time2?
© Stack Overflow or respective owner