Hi,
can any one solve this problem ..,
i couldn`t identify why its showing ParseException. .,
Following the code.....,
Output:java.tex t.ParseExceptio n: Unparseable date 2008/01/05
import java.util.*;
import java.text.*;
class CompareDates {
public static void main(String[] args) throws ParseException {
try
{
SimpleDateForma t df = new SimpleDateForma t (" yyyy-MM-dd");
//System.out.prin tln("it is " + df.format(d1));
Date d1 = new Date();
System.out.prin tln("it is " + df.format(d1));
String s = "2008/01/05";
//System.out.prin tln(" " + s);
Date d2 = df.parse(s); // Get Date 2
System.out.prin tln(" " + df.parse(s));
String relation;
if (d1.equals(d2))
relation = "the same date as";
//System.out.prin tln(d1 + " is " + relation + " " + d2);}
else if (d1.before(d2))
relation = "before";
//System.out.prin tln(d1 + " is " + relation + " " + d2);
else
relation = "after";
System.out.prin tln(d1 + " is " + relation + " " + d2);
} catch (ParseException e)
{
System.out.prin t(e);
}
}
}
can any one solve this problem ..,
i couldn`t identify why its showing ParseException. .,
Following the code.....,
Output:java.tex t.ParseExceptio n: Unparseable date 2008/01/05
import java.util.*;
import java.text.*;
class CompareDates {
public static void main(String[] args) throws ParseException {
try
{
SimpleDateForma t df = new SimpleDateForma t (" yyyy-MM-dd");
//System.out.prin tln("it is " + df.format(d1));
Date d1 = new Date();
System.out.prin tln("it is " + df.format(d1));
String s = "2008/01/05";
//System.out.prin tln(" " + s);
Date d2 = df.parse(s); // Get Date 2
System.out.prin tln(" " + df.parse(s));
String relation;
if (d1.equals(d2))
relation = "the same date as";
//System.out.prin tln(d1 + " is " + relation + " " + d2);}
else if (d1.before(d2))
relation = "before";
//System.out.prin tln(d1 + " is " + relation + " " + d2);
else
relation = "after";
System.out.prin tln(d1 + " is " + relation + " " + d2);
} catch (ParseException e)
{
System.out.prin t(e);
}
}
}
Comment