M
Mr B
Hi all,
I've been trying in vein to work this out but i simply can't find a
way of doing it. I'm trying to compare a date stored to the current
date, but I want to find out whether or not a date is 2 days older
than the date now. in the example below i used a String to store the
Date for compairing but it doesn't matter what I use to store this
information. I used the CompareTo method but found this only returned
1, 0 or -1.
public static void main(String[] args) throws java.text.ParseException
{
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
java.util.Date now = new java.util.Date();
String Date1 = "09-03-2007";
String Date2 = "12-03-2007";
java.util.Date trade = sdf.parse(Date1);
System.out.println(trade.compareTo(now));
}
Is there any way of achieving what I need?
Thanks
Daniel
I've been trying in vein to work this out but i simply can't find a
way of doing it. I'm trying to compare a date stored to the current
date, but I want to find out whether or not a date is 2 days older
than the date now. in the example below i used a String to store the
Date for compairing but it doesn't matter what I use to store this
information. I used the CompareTo method but found this only returned
1, 0 or -1.
public static void main(String[] args) throws java.text.ParseException
{
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
java.util.Date now = new java.util.Date();
String Date1 = "09-03-2007";
String Date2 = "12-03-2007";
java.util.Date trade = sdf.parse(Date1);
System.out.println(trade.compareTo(now));
}
Is there any way of achieving what I need?
Thanks
Daniel