zoukankan      html  css  js  c++  java
  • IE11浏览器传时间格式不兼容,c.a.d.c.advice.AdcDaBaseExceptionAdvice : JSON parse error

    时间是在后端获取的时间戳,格式后保存到后端(因为是编辑的情况下用的,没有编辑时间,所以又存回去),

    在IE浏览器和360的情况下,会报下面的错误。

    2018-03-16 17:00:02.092 ERROR 14300 --- [nio-8082-exec-6] c.a.d.c.advice.AdcDaBaseExceptionAdvice : JSON parse error: Can not deserialize value of type java.util.Date from String "‎2018‎年‎3‎月‎16‎日": not a valid representation (error: Failed to parse Date value '‎2018‎年‎3‎月‎16‎日': Can not parse date "‎2018‎年‎3‎月‎16‎日": not compatible with any of standard forms ("yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "EEE, dd MMM yyyy HH:mm:ss zzz", "yyyy-MM-dd")); nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Can not deserialize value of type java.util.Date from String "‎2018‎年‎3‎月‎16‎日": not a valid representation (error: Failed to parse Date value '‎2018‎年‎3‎月‎16‎日': Can not parse date "‎2018‎年‎3‎月‎16‎日": not compatible with any of standard forms ("yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "EEE, dd MMM yyyy HH:mm:ss zzz", "yyyy-MM-dd"))
    at [Source: java.io.PushbackInputStream@402d6af4; line: 1, column: 97] (through reference chain: com.adc.da.platformSetting.vo.AdverMsgVO["expirationDate"])

    org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Can not deserialize value of type java.util.Date from String "‎2018‎年‎3‎月‎16‎日": not a valid representation (error: Failed to parse Date value '‎2018‎年‎3‎月‎16‎日': Can not parse date "‎2018‎年‎3‎月‎16‎日": not compatible with any of standard forms ("yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "EEE, dd MMM yyyy HH:mm:ss zzz", "yyyy-MM-dd")); nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Can not deserialize value of type java.util.Date from String "‎2018‎年‎3‎月‎16‎日": not a valid representation (error: Failed to parse Date value '‎2018‎年‎3‎月‎16‎日': Can not parse date "‎2018‎年‎3‎月‎16‎日": not compatible with any of standard forms ("yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "EEE, dd MMM yyyy HH:mm:ss zzz", "yyyy-MM-dd"))
    at [Source: java.io.PushbackInputStream@402d6af4; line: 1, column: 97] (through reference chain: com.adc.da.platformSetting.vo.AdverMsgVO["expirationDate"])
    at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:244) ~[spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.read(AbstractJackson2HttpMessageConverter.java:229) ~[spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:201) ~[spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:150) ~[spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:128) ~[spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121) ~[spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:158) ~[spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:128) ~[spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97) ~[spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) ~[spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) ~[spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967) ~[spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901) ~[spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) ~[spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.doPut(FrameworkServlet.java:883) ~[spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:664) [tomcat-embed-core-8.5.15.jar:8.5.15]
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) ~[spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) [tomcat-embed-core-8.5.15.jar:8.5.15]

    开始是用下面代码的 type=3的格式化后请求后端的。后来查询ie不能这样添加“-”,更改为下面的type=4.可以了。

    function timeFormat(str,type) {
    if(type == 1){
    var regDate = ///g;
    return new Date(str).toLocaleDateString().replace(regDate,'-');
    }
    if(type == 2){
    var regDate2 = /-/g;
    return $(str).val().replace(regDate2,'/');
    }
    if(type == 3){
    var regDate = ///g;
    var showTime = new Date(str).toLocaleTimeString();
    return new Date(str).toLocaleDateString().replace(regDate,'-')+' '+showTime;
    }
    if(type == 4){
    var dataTime = new Date(str);
    var getYear = dataTime.getFullYear();
    var getMonth = dataTime.getMonth()+1;
    var getDate = dataTime.getDate();
    var newDate = getYear+'-'+getMonth+'-'+getDate;
    return newDate;
    }
    }


  • 相关阅读:
    leetcode ---Search a 2D Matrix
    leetcode ---Search for a Range
    LeetCode--Search in Rotated Sorted Array
    LeetCode--setatrixzeroes
    LeetCode--sortColor
    LeetCode--Spiral Matrix
    java io类 和servlet类 的UML图表示
    servlet web.xml配置详解
    解决json日期格式带T问题
    在拦截器中获取请求参数,[Ljava.lang.String; cannot be cast to java.lang.String报错
  • 原文地址:https://www.cnblogs.com/daguozb/p/8583467.html
Copyright © 2011-2022 走看看