JS type conversion date UTC

Front to take a date type UTC, "yyyy-MM-dd'T'HH: mm: ss.SSS", receives the background given as follows:

org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value 
of type `java.util.Date` from String "2019-08-10T02:37:54.770Z": not a valid representation 
(error: Failed to parse Date value '2019-08-10T02:37:54.770Z': Unparseable date: "2019-08-10T02:37:54.770Z");
nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: 
Cannot deserialize value of type `java.util.Date` from String "2019-08-10T02:37:54.770Z": 
not a valid representation (error: Failed to parse Date value '2019-08-10T02:37:54.770Z': Unparseable date: "2019-08-10T02:37:54.770Z")

The reason can not be resolved to a value of type UTC Spring date for the Date format, the solution is as follows:

formatTime(time, format) {
        var date = new Date(time);
        var formatter = function (i) { return (i < 10 ? '0' : '') + i };
        return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function (a) {
          switch (a) {
            case 'yyyy':
              return formatter(date.getFullYear());
              break;
            case 'MM':
              return formatter(date.getMonth() + 1);
              break;
            case 'mm':
              return formatter(date.getMinutes());
              break;
            case 'dd':
              return formatter(date.getDate());
              break;
            case 'HH':
              return formatter(date.getHours());
              break;
            case 'ss':
              return formatter(date.getSeconds());
              break;
          }
        })
      }

Js call this method is converted to the corresponding values ​​Date Date Type:

formatTime(changeDate,'yyyy-MM-dd HH:mm:ss')

Guess you like

Origin www.cnblogs.com/maggieq8324/p/11414753.html