Wednesday, 23 January 2013

Add AM PM to time using SimpleDateFormat

Leave a Comment

package Time;
import java.text.SimpleDateFormat;
import java.util.Date;

public class AddAMPMToFormattedDate {

  public static void main(String[] args) {

    //create Date object
    Date date = new Date();
     //formatting time to have AM/PM text using 'a' format
     String strDateFormat = "yyyy-MM-dd HH:mm:ss a";
     SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat);
     System.out.println("Time with AM/PM field : " + sdf.format(date));


Time with AM/PM field : 24:01:2013 10:33:50 AM


Post a Comment