Reputation: 2471
I am comparing the given date
with the current
date but it gives me an error of Unparseable date at ofset 4
. The date is looks like this 2010-03-25
. This is the line where the logcat pointing me towards strDate = sdf.parse(item.dateUpdated());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/mm/dd");
Date strDate;
try {
strDate = sdf.parse(item.dateUpdated());
if (System.currentTimeMillis() > strDate.getTime()) {
System.out.println("Date not matched");
}
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Upvotes: 1
Views: 51
Reputation: 5260
do it as folows
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");
Date strDate;
try {
strDate = sdf.parse("2010-03-25");
if (System.currentTimeMillis() > strDate.getTime()) {
System.out.println("Date not matched");
}
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
as yous SimpleDateFormat("yyyy/mm/dd");
is having yyyy/mm/dd while you are passing as 2010-03-25
so use SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");
instead of SimpleDateFormat sdf = new SimpleDateFormat("yyyy/mm/dd");
otherwisely it will say
java.text.ParseException: Unparseable date: "2010-03-25"
at java.text.DateFormat.parse(DateFormat.java:357)
Upvotes: 1