In my app i count no of days difference between old date and new date with the following code. it work good on android 2.2 and 2.3.6 devices but on android 4.0 device it is get crashed with java.lang.IllegalArgumentException
. i do not know sdk 4.0 does not support my code. please help me.
my code is :
Date date;
String old_Date = null;
.....
date = new Date();
old_Date = date.toString(); // i am storing it in sharedPreference so that i convert to string
.......
date = new Date();
long diff = calculate_dateDifference(date,new Date(old_Date)); // line no 65.
...
and my method:
protected long calculate_dateDifference(Date newerDate, Date olderDate) {
return (newerDate.getTime() - olderDate.getTime()) / (1000 * 60 * 60 * 24);
}
my sample log cat:
Caused by: java.lang.IllegalArgumentException
at java.util.Date.parse(Date.java:506)
at java.util.Date.<init>(Date.java:149)
at com.xxx.zzz.MainActivity.onCreate(MainActivity.java:65)