December 21st, 2011, 03:45 AM
String to Date conversion issue
I am trying to convert the string date to actual date using SimpleDateFormat class. But it seems the SimpleDateFormat class is returning the invalid value for the date object. It is increasing the minute value by 1. I am not sure if it's an actual issue with SimpleDateFormat class or my way of conversion is wrong. Any help ?
The code :
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.ms'Z'");
Date date = dateFormat.parse("2011-12-20T15:08:14.917Z");
System.out.println("Date: " + date);
It is displaying "Tue Dec 20 15:09:17 IST 2011" instead of "Tue Dec 20 15:08:14 IST 2011".
Thanks in advance.
December 21st, 2011, 05:49 AM
Re: String to Date conversion issue
The problem is with your format string, it should be:
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SS'Z'");
Tags for this Thread
Click Here to Expand Forum to Full Width