Format time to just hour and minute with Formatter in Java
Description
The following code shows how to format time to just hour and minute with Formatter.
Example
// w ww . j a v a 2s. co m
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 just hour and minute.
fmt = new Formatter();
fmt.format("%tl:%tM", cal, cal);
System.out.println(fmt);
}
}
The code above generates the following result.