What Java Date Format to correctly parse?

George Hernando

I have some code like the following:

import java.text.DateFormat;
...

this.timestampFormat = new SimpleDateFormat(timestampFormat, Locale.UK);
this.timestampFormat.parse(modifyTimestamp.get().toString());

But the parsing throws an error:

Caused by: java.text.ParseException: Unparseable date: "20150429142243.925Z"

I tried both these date format strings:

yyyyMMddHHmmss'Z'
yyyyMMddHHmmss'.0Z'

The "925Z" part of the time I think is the problem. Should the second date format string be correct in this case, although it isn't working.

Rahul Tripathi

Try this:

SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss.SSS'Z'", Locale.UK);

925 is the millisecond, so you need SSS to represent that as well.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related