JSR310 时间类型转换
1 | final java.util.Date date = new java.util.Date(); |
转 Instant
1 | // java.util.Date 转 Instant |
转 LocalDateTime
1 | // java.util.Date 转 LocalDateTime |
转 ZonedDateTime
1 | // java.util.Date 转 ZonedDateTime |
转 java.util.Date
1 | // Timestamp 转 Date |
转 Timestamp
1 | // java.util.Date 转 Timestamp |
转 Calendar
1 | // java.util.Date 转 Calendar |
转载自 JSR310 时间类型转换
FAQ:
1 | 2017-08-16 11:08:49.729 WARN 28128 --- [ XNIO-2 task-1] .m.m.a.ExceptionHandlerExceptionResolver : Resolved exception caused by Handler execution: org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.time.ZonedDateTime'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@org.springframework.web.bind.annotation.RequestParam @org.springframework.format.annotation.DateTimeFormat java.time.ZonedDateTime] for value '02/17/2011'; nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value [02/17/2011]. |
接收的数据只有 date,目标类型是 date 和 time。
如果长时间无法加载,请针对 disq.us | disquscdn.com | disqus.com 启用代理