(java) 全局处理异常捕获 报错

代码

public Map<String, Object> getMyRollsJSONObject head,JSONObject body throws Exception { // 业务信息 Map<String, Object> attributes=new HashMap<String, Object>; //cityCode // String cityCode=head.optString"cityCode"; // cityCode=GetCItyCode.getCityCodecityCode; String page=body.optString"page"; String rows=body.optString"rows"; int type=body.optInt"type"; String token=head.optString"token"; Object object=UserCacheManage.getAppUsertoken; UserCache user=UserCacheobject; String userId="4028668150c6aedb0150c6ddde750005"; HhUserEntity hhUserEntity=super.getEntityHhUserEntity.class, userId; ifhhUserEntity!=null{ String nowTime=DateUtils.formatTime; String queryString = "SELECT COUNTc.couponname, c.couponname,c.couponfee/100,c.pic1_path,date_formatc.endtime,%Y-%c-%d as endTime FROM couponpublish c,couponpool s WHERE s.pubid=c.pubid AND s.owner="+userId+""; String whereString=""; //优惠卷类别 1.可用;2.历史 iftype==1{ whereString=whereString+" and "+nowTime+" between c.starttime and c.endtime and s.status=3 "; }else{ whereString=whereString+" and "+nowTime+" > c.endtime or s.status>3 "; } String orderString=" order by c.updatetime "; int offset=PagerUtil.getOffsetInteger.valueOfpage,Integer.valueOfrows; List<Map> list=super.findListbySqlReturnMapByPagequeryString+whereString, offset, Integer.valueOfrows; String flag = ""; Map e = new HashMap<String, Object>; String endTime = String list.get0.get"endTime"; long now= Long.parseLongnowTime; long end = Long.parseLongendTime; long f = now-end; iff>3{ e.put"flag",new String"过期"; list.adde; } System.out.printlnlist; attributes.put"coupons", list; }else{ throw new InterfaceExceptionnew ErrorBeanErrorCode.USER_NO_LOGIN; } return attributes; }

报错:
[org.jeecgframework.core.common.exception.GlobalExceptionResolver]全局处理异常捕获:
java.lang.NumberFormatException: For input string: “2016-03-15 10:18”

at java.lang.NumberFormatException.forInputStringUnknown Source
at java.lang.Long.parseLongUnknown Source
at java.lang.Long.parseLongUnknown Source
at com.sendiy.hh.client.service.impl.ClientMyCouponsServiceImpl.getMyRollsClientMyCouponsServiceImpl.java:78
at sun.reflect.NativeMethodAccessorImpl.invoke0Native Method
at sun.reflect.NativeMethodAccessorImpl.invokeUnknown Source
at sun.reflect.DelegatingMethodAccessorImpl.invokeUnknown Source
at java.lang.reflect.Method.invokeUnknown Source
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflectionAopUtils.java:318
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpointReflectiveMethodInvocation.java:183
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceedReflectiveMethodInvocation.java:150
at org.springframework.transaction.interceptor.TransactionInterceptor.invokeTransactionInterceptor.java:110
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceedReflectiveMethodInvocation.java:172
at org.springframework.aop.framework.JdkDynamicAopProxy.invokeJdkDynamicAopProxy.java:202
at com.sun.proxy.$Proxy71.getMyRollsUnknown Source
at com.sendiy.hh.client.controller.GetMyRollsController.getMyRollsGetMyRollsController.java:46
at sun.reflect.NativeMethodAccessorImpl.invoke0Native Method
at sun.reflect.NativeMethodAccessorImpl.invokeUnknown Source
at sun.reflect.DelegatingMethodAccessorImpl.invokeUnknown Source
at java.lang.reflect.Method.invokeUnknown Source
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethodHandlerMethodInvoker.java:176
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethodAnnotationMethodHandlerAdapter.java:436
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handleAnnotationMethodHandlerAdapter.java:424
at org.springframework.web.servlet.DispatcherServlet.doDispatchDispatcherServlet.java:923
at org.springframework.web.servlet.DispatcherServlet.doServiceDispatcherServlet.java:852
at org.springframework.web.servlet.FrameworkServlet.processRequestFrameworkServlet.java:882
at org.springframework.web.servlet.FrameworkServlet.doPostFrameworkServlet.java:789
at javax.servlet.http.HttpServlet.serviceHttpServlet.java:646
at javax.servlet.http.HttpServlet.serviceHttpServlet.java:727
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilterApplicationFilterChain.java:303
at org.apache.catalina.core.ApplicationFilterChain.doFilterApplicationFilterChain.java:208
at org.apache.tomcat.websocket.server.WsFilter.doFilterWsFilter.java:52 我加上
String endTime = String list.get0.get"endTime"; long now= Long.parseLongnowTime; long end = Long.parseLongendTime; long f = now-end; iff>3{ e.put"flag",new String"过期"; list.adde; } 这几行代码之后报错,我要endtime和现在时间是不是差3天。 

字符串 “2016-03-15 10:18” 直接转时间戳吗?

传统:先转成date,然后getTime,时间戳层面上进行比较
新:

 SimpleDateFormat toFormate = new SimpleDateFormat"yyyy-MM-dd "; Calendar cal = Calendar.getInstance; String now = toFormate.formatcal.getTime; cal.addCalendar.DATE, -1; String yesterday = toFormate.formatcal.getTime; cal.addCalendar.DATE, -7; String weeked = toFormate.formatcal.getTime;

发表评论

电子邮件地址不会被公开。 必填项已用*标注