Time in 24-hour format in java.
Time in 24-hour format in java.
In this section, you will see how to display time in 24-hour format in java. Here, we are passing a string argument in SimpleDateFormat class constructor. this string argument holds format of time, in which you wants to display your time.
HH:mm:ss --- Hours(1-24) : Minutes : Second
Code:
TimeIn24Format.javaimport java.text.SimpleDateFormat; import java.util.Calendar; public class TimeIn24Format { public static void main(String[] arr) { String timeformat = "HH:mm:ss"; SimpleDateFormat obDateFormat = new SimpleDateFormat(timeformat); Calendar time = Calendar.getInstance(); System.out.println("Time in 24-hour format :" + obDateFormat.format(time.getTime())); } }
Output
Time in 24-hour format :15:05:57 |
[ 0 ] Comments