I'm converting a string to Date in Java, but I having a problem It is adding some extra minutes to the result Date.
The String has the following format "yyyy-MM-dd HH:mm:ss.sss" and I have created this function:
public static Date parseISO8601(String date) {
Date result = null;
try {
if (!TextUtils.isEmpty(date)) {
SimpleDateFormat dateFormat = new SimpleDateFormat(
ISO8601_DATE_FORMAT);
result = dateFormat.parse(date);
}
}
catch (Exception ex){
return null;
}
return result;
}
public static final String ISO8601_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss.sss";
When I use this function with this string "2015-06-11 20:17:56.873" the result is "Thu Jun 11 20:31:33 CST 2015". I am really new coding with Java, I have read a lot of posts but for me everything seems normal, I don´t know why this is happening.
Some ideas?
Try this instead:
yyyy-MM-dd HH:mm:ss.SSS
You are using 's' instead of 'S" for millis.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With