栏目:Java8基础 作者:admin 日期:2015-07-12 评论:3 点击: 6,450 次
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 毫秒数
------====== 本站公告 ======------
金丝燕网,一个严谨的网站!