java字符串yyyyMMdd格式化为yyyy-MM-dd日期格式(2种方式)
简单的东西不解释直接上代码:StringBuffer s=new StringBuffer("20190305").insert(4,"-").insert(7,"-");System.out.println(s);=============================================================================pub...
·
简单的东西不解释直接上代码:
StringBuffer s=new StringBuffer("20190305").insert(4,"-").insert(7,"-");
System.out.println(s);
=============================================================================
public String strToDateFormat(String date) throws ParseException {
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
formatter.setLenient(false);
Date newDate= formatter.parse(date);
formatter = new SimpleDateFormat("yyyy-MM-dd");
return formatter.format(newDate);
}
try {
System.out.println(this.strToDateFormat("20190305"));
} catch (ParseException e) {
e.printStackTrace();
}
更多推荐
所有评论(0)