Java examples for Date Time:SimpleDateFormat
Add AM PM to time using SimpleDateFormat
import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static void main(String[] args) { Date date = new Date(); /*from ww w . j av a 2 s . c om*/ //formatting time to have AM/PM text using 'a' format String strDateFormat = "HH:mm:ss a"; SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat); System.out.println("Time with AM/PM field : " + sdf.format(date)); } }