Get current time information in Java
Description
The following code shows how to get current time information.
Example
/*from w w w .jav a 2 s . c om*/
import java.util.Calendar;
public class Main {
public static void main(String[] args) {
Calendar now = Calendar.getInstance();
System.out.println("Current Hour in 12 hour format is : " + now.get(Calendar.HOUR));
System.out.println("Current Hour in 24 hour format is : " + now.get(Calendar.HOUR_OF_DAY));
System.out.println("Current Minute is : " + now.get(Calendar.MINUTE));
System.out.println("Current Second is : " + now.get(Calendar.SECOND));
System.out.println("Current Millisecond is : " + now.get(Calendar.MILLISECOND));
}
}
The code above generates the following result.