// 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());