将String类型的日期转换为Date
java.lang.IllegalArgumentException: Cannot format given Object as a Date
String time = studentAwardDetailPO.getCreateTime();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
String formatTime = simpleDateFormat.format(time);
一开始仅使用SimpleDateFormat格式化time,format(Date date) 这个方法的参数只能是Date类型的, 而这里传递的是String类型,所以是有错误的。
加上一个DateFormat,parse方法将String类型转化为Date类型,就可以使用format了。
String time = studentAwardDetailPO.getCreateTime();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
try {
Date day = dateFormat.parse(time);
String formatTime = simpleDateFormat.format(day);
}catch (ParseException e) {
e.printStackTrace();
}