1. String类型的时间转为DateTime
public static Date transferString2Date(String s) { Date date = new Date(); try { date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(s); } catch (ParseException e) { //LOGGER.error("时间转换错误, string = {}", s, e); } return date; }
2. String类型的时间转为Date
public static Date transferString2Date(String s) { Date date = new Date(); try { date = new SimpleDateFormat("yyyy-MM-dd").parse(s); } catch (ParseException e) { //LOGGER.error("时间转换错误, string = {}", s, e); } return date; }
3.Date类型的时间转为String
Date date = new Date(); SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss SSS"); String dateStr = fmt.format(date);
标签:String,SimpleDateFormat,date,时间,Date,new From: https://www.cnblogs.com/fkbzr1998/p/16838709.html