1、将Date类型转换成String类型
日期精确到秒:
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
String str = sdf.format(date);
日期精确到天:
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
String str = sdf.format(date.getTime());
2、将String类型转换成Date类型
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); try { date = sdf.parse(effDate); }catch (Exception e){ return RestResponse.error("日期格式错误"); }