Format date with hh:mm:ss a in Java
Description
The following code shows how to format date with hh:mm:ss a.
Example
/*from w w w.j a va 2 s . c o m*/
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Main {
public static void main(String[] argv) throws Exception {
Date date = new Date();
Format formatter = new SimpleDateFormat("hh:mm:ss a");
String s = formatter.format(date);
System.out.println(s);
}
}
The code above generates the following result.