Java SimpleDateFormat format time as AM PM

Description

Java SimpleDateFormat format time as AM PM

import java.text.SimpleDateFormat;
import java.util.Date;
 
public class Main {
 
  public static void main(String[] args) {
    Date date = new Date();
   /*  www  .  j a va2  s  . c  o m*/
    //formatting time to have AM/PM text using 'a' format
    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss a");
     
    System.out.println("Time with AM/PM field : " + sdf.format(date));
 
  }
}



PreviousNext

Related