Android Date incorrect results
I am getting the dates from twitter status feed.
I am trying to find out all the latest updates (past 24 hours)
long referenceTime =System.currentTimeMillis()-(24*60*60*1000);
//ti.getDateTime() returns the string time returned from twitter..
long statusTime =DateUtil.convertStringToDate(ti.getDateTime(), "EEE MMM dd HH:mm:ss ZZZZZ yyyy").getTime();
if(statusTime>referenceTime )
{
Log.d(TAG,"Recent update");
}
Now for the following dates it returns as 开发者_如何学编程"Recent update" //Current system time 9:52 am sep 30 2011
Thu Sep 29 11:28:16 +0000 2011 // Correct
Thu Sep 29 11:33:07 +0000 2011 // Correct
Fri Mar 25 16:15:05 +0000 2011 // Incorrect
Tue Mar 22 19:32:38 +0000 2011 // Incorrect
Sat Jul 24 12:05:49 +0000 2010 // Incorrect
Wed Jul 14 23:56:27 +0000 2010 // Incorrect
[These are the strings that ti.getDateTime() returns.] Why is it happening so ?
and its pretty much random since the following dates the log is not printed.
Fri Jul 09 22:07:53 +0000 2010
Fri Jul 09 21:17:23 +0000 2010
Tue Apr 26 22:33:59 +0000 2011
DateUtil :
public static final Date convertStringToDate(String date, String entryFormat) {
Date theDate = null;
try {
//SimpleDateFormat formatter = new SimpleDateFormat( "MMMM d, yyyy");"yyyy-mm-dd"
SimpleDateFormat formatter = new SimpleDateFormat( entryFormat);
theDate = formatter.parse(date);
} catch (Exception e){
}
return theDate;
}
精彩评论