Display current time in 12 hour format with AM/PM
use "hh:mm a"
instead of "HH:mm a"
. Here hh
for 12 hour format and HH
for 24 hour format.
Live Demo
Use this SimpleDateFormat formatDate = new SimpleDateFormat("hh:mm a");
Java docs for SimpleDateFormat
Easiest way to get it by using date pattern - h:mm a
, where
- h - Hour in am/pm (1-12)
- m - Minute in hour
- a - Am/pm marker
Code snippet :
DateFormat dateFormat = new SimpleDateFormat("hh:mm a");
Read more on documentation - SimpleDateFormat java 7