I want to parse a timestamp in the form of yyyy-MM-dd'T'HH:mm:ss as LocalDateTime. When doing so, it strips the seconds if they are 00.
As described here, I need to use a custom formatter
LocalDateTime date = LocalDateTime.parse("2008-10-02T12:30:00");
DateTimeFormatter f = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
String dateString = date.toString();
String dateFormatted = date.format(f);
System.out.println(dateString); // 2008-10-02T12:30
This one works, but it returns a String:
System.out.println(dateFormatted); // 2008-10-02T12:30:00
When I parse the string to LocalDateTime it strips the 00 again:
LocalDateTime dateLDT = LocalDateTime.parse(dateFormatted, f);
System.out.println(dateLDT); // 2008-10-02T12:30
So how can I parse a date as LocalDateTime, instead of String, and keep the 00 at the end?