java 时间格式转换

// parse将字符串解析成Date 
String createDate = req.getParameter("createDate");
SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
      Date dates = sim.parse(createDate);
      post.setCreateDate(dates);
 
} catch (ParseException e) {
              e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
} 
// format格式化代码,将data转化为String Date da=new Date(); SimpleDateFormat format=new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss"); String times=format.format(da);
// 获得分钟 String minute = new SimpleDateFormat("mm").format(new Date());
原文地址:https://www.cnblogs.com/lixin890808/p/3028558.html