How to convert a time that is input in h:mm format to hh:mm format?

619 views Asked by At

From a time input in format 5:00 to 05:00!

in arr[1] there is "5:00" <--string format

 DateTimeFormatter time=DateTimeFormatter.ofPattern("HH:mm");
 LocalTime arr1 = LocalTime.parse((CharSequence) time.parse(arr[1]));
1

There are 1 answers

1
Ansar Ozden On

Works for me.

  @Test
  void localTimeFormatTest() {
    LocalTime time = LocalTime.parse("5:00", DateTimeFormatter.ofPattern("H:mm"));
    
    String result = time.format(DateTimeFormatter.ofPattern("HH:mm"));
    
    assertThat(result).isEqualTo("05:00");
  }