提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
使用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*/