I want to sort the posts by date("hh:mm:ss"). but I get a mistake. Can you tell me what I did wrong?
java.time.format.DateTimeParseException: Text '12:55:36' could not be parsed: Unable to obtain LocalDateTime from TemporalAccessor: {HourOfAmPm=0, MinuteOfHour=55, SecondOfMinute=36, MicroOfSecond=0, MilliOfSecond=0, NanoOfSecond=0}
class PostX {
int id;
String name;
int score;
String timePublication;
public PostX(int id, String name, int score, String timePublication) {
this.id = id;
this.name = name;
this.score = score;
this.timePublication = timePublication;
}
public static void main(String[] args) {
List<PostX> posts = List.of(
new PostX(1,"post1", 10, "20:55:36"),
new PostX(2,"post2", 0, "12:55:36"),
new PostX(3,"post3", 100, "19:55:36"),
new PostX(4,"post4", 1000, "23:55:36"),
new PostX(5,"post5", 10, "01:50:36"),
new PostX(6,"post6", 3, "20:55:36"),
new PostX(7,"post7", 4, "20:15:36"),
);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("hh:mm:ss");
List<PostX> posts1 = posts.stream()
.sorted(Comparator.comparing(o -> LocalDateTime.parse(o.timePublication, formatter))).limit(5).toList();
}
}