Java将Date转换为特定的String格式
示例
format()fromSimpleDateFormat类可通过使用提供的模式字符串将Date对象转换为特定格式的String对象。
Date today = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMM-yy"); //模式在这里指定
System.out.println(dateFormat.format(today)); //25-Feb-16可以通过使用再次应用图案applyPattern()
dateFormat.applyPattern("dd-MM-yyyy");
System.out.println(dateFormat.format(today)); //25-02-2016
dateFormat.applyPattern("dd-MM-yyyy HH:mm:ss E");
System.out.println(dateFormat.format(today)); //25-02-201606:14:33星期四注意:此处mm(小写字母m)表示分钟,MM(大写字母M)表示月份。格式化年份时请格外注意:大写Y字母“Y”(y)表示“一年中的星期”,小写字母“y”()表示年份。
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短