Parse String date in (yyyy.MM.dd HH.mm.ss.S) format

user1168608 picture user1168608 · Nov 18, 2016 · Viewed 10.5k times · Source

I want the Input string which is of pattern "yyyy.MM.dd HH.mm.ss.S" to be converted to Date. The Input string is 1988.07.29 12:12:12.123

I have done it in the following way:

SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
Date date = dateFormat.parse(value);

I get ParseException saying the entered date is unparseable.

First Thing, does my pattern correspond to the Input string? If yes what am i doing wrong here?

Answer

M A picture M A · Nov 18, 2016

You have to use colons instead of dots in the pattern:

yyyy.MM.dd HH:mm:ss.S

Characters from A to Z and from a to z are interpreted as special characters. All other characters in the pattern are matched as they are. See https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html for more details.