What I have
I have a server date in w3c date format
2016-02-13T09:53:49.871Z for notification
What I want
I wanted to convert the w3c format
to device time zone
then get the current date from the device to check whether sever date
is equal to device date
My problem
I get Parse error: 2016-03-10 15:45:36
at Date formattedServerDeviceDate=new Date(serverDateDeviceFormat);
My code
public boolean isTodaysNotification(String serverDate)throws Exception{
boolean isTodaysNotification=false;
SimpleDateFormat simpleDateFormatW3C = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
simpleDateFormatW3C.setTimeZone(TimeZone.getTimeZone("GMT"));
Date dateServer = simpleDateFormatW3C.parse(serverDate);
TimeZone deviceTimeZone = TimeZone.getDefault();
SimpleDateFormat simpleDeviceFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
simpleDeviceFormat.setTimeZone(deviceTimeZone);
String serverDateDeviceFormat = simpleDeviceFormat.format(dateServer);
Date formattedServerDeviceDate=new Date(serverDateDeviceFormat); // formatted to device time zone (w3c to utc)
SimpleDateFormat simpleFormat = new SimpleDateFormat("yyyy-MM-dd"); // formatting to consider only "yyyy-MM-dd"
String strServerDate=simpleFormat.format(formattedServerDeviceDate); // server date
String strTodaysDate=simpleFormat.format(new Date()); // current date
if (new Date(strTodaysDate).compareTo(new Date(strServerDate))==0){
isTodaysNotification=true;
}
else {
isTodaysNotification=false;
}
return isTodaysNotification;
}