| Author |
Date Comparision
|
sreedhar Lackka
Ranch Hand
Joined: Jul 05, 2008
Posts: 154
|
|
Hi All,
Thanks in advance.
I would like to do the date comparision in Java without any caluculations like days*hours....
Just want to know whether the two selected days difference is below one year.
Please advice and give me some example code.
Thanks & Regards,
Sreedhar
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12929
|
|
So, you have two Date objects, let's say date1 and date2, where date1 is before date2, and you want to know if the time between them is less than one year.
One way to do this with Java's standard date and time API is like this:
Get a Calendar object and set it to the value of date2.Use Calendar's methods to subtract one year.Check if the date that the calendar is set to is before date1. If this is true, then the time between date1 and date2 is less than one year.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
 |
|
|
subject: Date Comparision
|
|
|