So I am trying to parse a date string in Java. I am getting the correct hours back but the minutes seem to be out by about 5-10. I am showing my code below along with the input string and the date Objects toString() output.
Any ideas where I am going wrong? This is on Android so I would prefer not to use JodaTime.
DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSS'Z'");
Date date = sdf.parse(input);
return date;
Input String = 2012-11-07T12:47:05.0581816Z
Date toString() = Wed Nov 07 12:56:46 GMT 2012 (Milliseconds = 1352293006816)
You are trying to parse a date with microsecond precision as millisecond precision.
0581816 is the number of milliseconds added to the time 12:47:05, not, as you probably expect, a decimal fraction of a second.
Since the precision below millisecond cannot be represented by
java.util.Date, the simplest option would be to truncate the decimal fraction and adjust the date format, as follows: