//string字符串转换为Date
public static Date formatDate(String str){
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");//这里只要年月日
Date date;
try {
//处理异常
date = format.parse(str);
return date ;
} catch (ParseException e) {
e.printStackTrace();
}
//str格式不对,返回null
return null ;
}
//Date转换为string字符串
public static String toDate(Date oldDate){
String resultDate = "";
if (oldDate == null){
return "";
}
SimpleDateFormat outDate =new SimpleDateFormat("yyyy-MM-dd");
resultDate = outDate.format(oldDate);
return resultDate;
}