SimpleDateFormat sdf = new SimpleDateFormat("yyyymmdd");
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy/mm/dd");
String date = "20100701";
String new_s = date.replaceAll("(\\d{4})(\\d{2})(\\d{2})", "$1/$2/$3");
try {
System.out.println(new_s);
System.out.println(sdf1.format(sdf.parse(date)));
} catch (ParseException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
本文演示了如何使用Java的SimpleDateFormat类进行日期格式的转换与解析,通过正则表达式实现日期字符串的格式化,并展示了两种日期格式输出的结果对比。
1661

被折叠的 条评论
为什么被折叠?



