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”()表示年份。
热门推荐
6 保研的祝福语简短
10 年轻20岁祝福语简短
11 朋友结婚祝福语信息简短
12 女孩婚礼贺卡祝福语简短
13 30段点歌简短祝福语
14 虎年春节祝福语图文简短
15 写给后妈祝福语大全简短
16 简短回复生日祝福语
17 校长送毕业祝福语简短
18 毕业立体贺卡祝福语简短