Time in 24-hour format in java.

Time in 24-hour format in java.


Posted in : Core Java Posted on : December 2, 2010 at 5:13 PM Comments : [ 0 ]

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.java
import 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

Download this code.

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics