qq_28573739 2016-03-15 03:07 采纳率: 100%
浏览 1553
已采纳

字符串时间比较报错问题

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)

  • 写回答

1条回答

  • danielinbiti 2016-03-15 03:27
    关注
      SimpleDateFormat toFormate = new SimpleDateFormat("yyyy-MM-dd ");
     改成
     SimpleDateFormat toFormate = new SimpleDateFormat("yyyy-MM-dd"); 多了一个空格
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器