Format date to standard 12-hour time in Java
Description
The following code shows how to format date to standard 12-hour time.
Example
//from ww w . j a va2s.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();
fmt.format("%tr", cal);
System.out.println(fmt);
}
}
The code above generates the following result.