I am using HH:mm
format to print the hour and minute in java. It will give the time in format
05:12
, 00:04
. But my requirement is to get with single digit hours:
05:12 => 5:12
00:04 => 0:04
10:18 => 10:18
Below i have the code which i am running to produce the date,
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
public class TestDateUtil {
public static void main(String ar[]) {
LocalTime time = LocalTime.now();
String t = time.format(DateTimeFormatter.ofPattern("HH:mm"));
System.out.println(t);
}
}
I know that i can use string operations to make the time split on the basis of : and then change that, but that too need a lot more variations of conditions checking which i don't want to do. Is there any way of doing it?