yyyyMMddHHmmss转换yyyy-MM-dd HH:mm:ss

原创连接:https://www.applebai.com/blog/details/36/20203274.html
jdk1.8

		DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
		LocalDateTime ldt = LocalDateTime.parse(datetime,dtf);
		DateTimeFormatter fa = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
		String datetime2 = ldt.format(fa);

jdk1.7

public static String strToDateFormat(String date) throws ParseException{
	       SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
	       formatter.setLenient(false);
	       Date newDate= formatter.parse(date);
	       formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	       return formatter.format(newDate);
	   }
©️2020 CSDN 皮肤主题: 技术工厂 设计师:CSDN官方博客 返回首页