SimpleDateFormat类的使用并不复杂,常用的方法在下面的例子就包含了:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 public class Test { public static void main(String[] args) { //利用构造函数设置格式化模板 SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日"); Date date = new Date(); //执行格式化功能 System.out.println(formatter.format(date)); //设置格式化模板 formatter.applyPattern("yyyy-MM-dd"); System.out.println(formatter.format(date)); } }在设置格式化模板的时候,要注意一些占位符所表示的含义:y 年 M 年中的月份D 年中的天数d 月份中的天数H 一天中的小时数(0-23)h am/pm 中的小时数(1-12)m 小时中的分钟数s 分钟中的秒数S 毫秒数
深入研究SimpleDateFormat
转载于:https://www.cnblogs.com/xuedexin/articles/5615686.html
