集册 Java实例教程 使用SimpleDateFormat将AM PM添加到时间

使用SimpleDateFormat将AM PM添加到时间

欢马劈雪     最近更新时间:2020-01-02 10:19:05

515
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
使用SimpleDateFormat将AM PM添加到时间


 
 /**来自 
  N  o w  J a v a . c o m**/

import java.text.SimpleDateFormat;

import java.util.Date;

 

public class Main {

 

  public static void main(String[] args) {

    Date date = new Date();

   

    //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));

 

  }

}/*from 时 代 J     a    v  a - nowjava.com*/