Standard 12-hour time format in Java
Description
The following code shows how to standard 12-hour time format.
Example
//from w w w . ja va2 s . c om
import java.util.Calendar;
import java.util.Formatter;
public class Main {
public static void main(String args[]) {
Formatter fmt = new Formatter();
Calendar cal = Calendar.getInstance();
// Display standard 12-hour time format.
fmt.format("%tr", cal);
System.out.println(fmt);
}
}
The code above generates the following result.