提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
使用转换字符t和T格式化日期和时间。
/* 时代Java 提 供 */ import java.util.Calendar; public class Main { public static void main(String[] args) { // get current date and time Calendar dateTime = Calendar.getInstance(); // printing with conversion characters for date/time compositions System.out.printf("%tc\n", dateTime); System.out.printf("%tF\n", dateTime); System.out.printf("%tD\n", dateTime);/** 时 代 J a v a 公 众 号 - nowjava.com 提供 **/ System.out.printf("%tr\n", dateTime); System.out.printf("%tT\n", dateTime); // printing with conversion characters for date System.out.printf("%1$tA, %1$tB %1$td, %1$tY\n", dateTime); System.out.printf("%1$TA, %1$TB %1$Td, %1$TY\n", dateTime); System.out.printf("%1$ta, %1$tb %1$te, %1$ty\n", dateTime);