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 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短