The question is published on by Tutorial Guruji team.
String timeColonPattern = "HH:mm:ss.SSSSSSSSS"; DateTimeFormatter timeColonFormatter = DateTimeFormatter.ofPattern(timeColonPattern); LocalTime colonTime = LocalTime.parse("09:30:23.187235");
I want “09:30:23.187235” to be converted into nanosecond precision. colonTime is same as 09:30:23.187235 but I want it to be converted into 09:30:23.187235000. i.e. It should add zeros if the digits after decimal is less than 9. Any suggestion how can I achieve that?
LocalTime colonTime = LocalTime.parse("09:30:23.187235"); System.out.println( DateTimeFormatter.ofPattern("HH:mm:ss.nnnnnnnnn") .format(colonTime) );
See this code run in IdeOne.com.
See all possible patterns see the