I have the following DateTimeFormatter
code
DateTimeFormatter sysDateFmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
And an example of the timestamp would be 2018-09-04 09:16:11.305
. The milliseconds have 3 digits. And the following code to parse the timestamp would just work fine.
LocalTime.parse("2018-09-04 09:16:11.305", sysDateFmt)
However, sometimes the millisecond part of the timestamp I encountered only have 2 digits, i.e. 2018-09-12 17:33:30.42
. Then this is where I come across the error below.
Exception in thread "main" java.time.format.DateTimeParseException: Text '2018-09-12 17:33:30.42' could not be parsed at index 20
What is the efficient solution to overcome this problem?