Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i tell if one joda-time DateTime object is within 4 hours of another?

Tags:

java

jodatime

What's the best way to tell if one joda time DateTime object is within 4 hours of another if I don't know which object is earlier than the other?

The Joda Time Duration object seems to do this job well if I know that object A comes before object B, but since Duration is signed it doesn't seem to do what I want if I don't know the order.

Seems like there would be an easy way to do this, but I haven't found it yet.

like image 905
emmby Avatar asked Jan 24 '23 04:01

emmby


1 Answers

Just use the Hours class for this:

Hours h = Hours.hoursBetween(date1, date2); 
int hours = h.getHours();
like image 80
MicSim Avatar answered Jan 29 '23 21:01

MicSim