问题描述
- 字符串时间比较报错问题
-
SimpleDateFormat toFormate = new SimpleDateFormat("yyyy-MM-dd ");
Calendar cal = Calendar.getInstance();
String now = toFormate.format(cal.getTime());
cal.add(Calendar.DATE, 3);
String yes = toFormate.format(cal.getTime());
toFormate.parse(yes);
toFormate.parse(endTime);
if((yes+3)==endTime){
e.put("flag","即将过期");
list.add(e);
}System.out.println(list); attributes.put("coupons", list); 报错:
[org.jeecgframework.core.common.exception.GlobalExceptionResolver]全局处理异常捕获:
java.text.ParseException: Unparseable date: "2015-12-25"
at java.text.DateFormat.parse(Unknown Source)
at com.sendiy.hh.client.service.impl.ClientMyCouponsServiceImpl.getMyRolls(ClientMyCouponsServiceImpl.java:89)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
解决方案
SimpleDateFormat toFormate = new SimpleDateFormat("yyyy-MM-dd ");
改成
SimpleDateFormat toFormate = new SimpleDateFormat("yyyy-MM-dd"); 多了一个空格
时间: 2024-10-14 23:04:11