I have a timestamp string from a service, it has 6 millisecond digits:
String timestamp = "2014-09-30T15:30:00.777777";
I am parsing it like so:
String format = "yyyy-MM-dd'T'HH:mm:ss.SSS";
DateFormat df = new SimpleDateFormat(format, Locale.ENGLISH);
Date date = df.parse(timestamp);
SimpleDateFormat df2 = new SimpleDateFormat();
System.out.println(df2.format(date));
I am expecting to see:
"9/30/14 3:30 PM"
but instead I get:
"9/30/14 3:42 PM"
twelve minutes ahead. I tried using a different format string with 6 ms digits:
String format = "yyyy-MM-dd'T'HH:mm:ss.SSSSSS";
Same result.
It seems what I have to do is manually truncate the incoming timestamp strings to 3 ms digits:
timestamp = timestamp.substring(0, timestamp.length()-3);
then I get the expected result. Or I can use a truncated format string that ignores milliseconds:
String format = "yyyy-MM-dd'T'HH:mm:ss";
Are those correct solutions? Am I just misusing SimpleDateFormat?
Thank you