Illegal instant due to time zone offset transition (Asia/Shanghai) - Joda.time

一,问题描述

  通过DateTime获取某年某月某日的时间戳,然后使用joda-time的Period.getYears()比较两个时间相差的年数。当new DateTime("1990-04-15")报错如下:

  

threw exception [Request processing failed; nested exception is org.joda.time.IllegalInstantException: Cannot parse "
1986-05-04": Illegal instant due to time zone offset transition (Asia/Shanghai)] with root cause]
org.joda.time.IllegalInstantException: Cannot parse "1986-05-04": Illegal instant due to time zone offset transition (Asia/Shanghai)
at org.joda.time.format.DateTimeParserBucket.computeMillis(DateTimeParserBucket.java:471) ~[joda-time-2.9.4.jar!/:2.9.4]
at org.joda.time.format.DateTimeParserBucket.computeMillis(DateTimeParserBucket.java:411) ~[joda-time-2.9.4.jar!/:2.9.4]
at org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:928) ~[joda-time-2.9.4.jar!/:2.9.4]
at org.joda.time.DateTime.parse(DateTime.java:160) ~[joda-time-2.9.4.jar!/:2.9.4]

 

通过遍历1900-2500年所有时间发现并不是所有时间都会报错,只有1940-06-03、1941-03-16、1986-05-04、1987-04-12、1988-04-10、1989-04-16、1990-04-15、1991-04-14几个时间会有如上错误抛出..

二 原因

  new DateTime("1990-04-15")时未指定时区,导致无法找到该时间对应的时间戳。

三,解决方案

  new DateTime("1990-04-15")时指定时区,如:new DateTime("1990-04-15", DateTimeZone.forID("+08:00"))

原文:https://blog.csdn.net/u010954806/article/details/79064130

转载于:https://www.cnblogs.com/yanglw/p/11303152.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by com.alipay.sofa.jraft.util.internal.UnsafeUtil (jar:file:/E:/service/nacos-server-2.2.3/nacos/target/nacos-server.jar!/BOOT-INF/lib/jraft-core-1.3.12.jar!/) to field java.nio.Buffer.address WARNING: Please consider reporting this to the maintainers of com.alipay.sofa.jraft.util.internal.UnsafeUtil WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be denied in a future release 2023-07-15 22:58:51,129 WARN Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'instanceOperatorClientImpl' defined in URL [jar:file:/E:/service/nacos-server-2.2.3/nacos/target/nacos-server.jar!/BOOT-INF/lib/nacos-naming-2.2.3.jar!/com/alibaba/nacos/naming/core/InstanceOperatorClientImpl.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'clientOperationServiceProxy' defined in URL [jar:file:/E:/service/nacos-server-2.2.3/nacos/target/nacos-server.jar!/BOOT-INF/lib/nacos-naming-2.2.3.jar!/com/alibaba/nacos/naming/core/v2/service/ClientOperationServiceProxy.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'persistentClientOperationServiceImpl' defined in URL [jar:file:/E:/service/nacos-server-2.2.3/nacos/target/nacos-server.jar!/BOOT-INF/lib/nacos-naming-2.2.3.jar!/com/alibaba/nacos/naming/core/v2/service/impl/PersistentClientOperationServiceImpl.class]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.alibaba.nacos.naming.core.v2.service.impl.PersistentClientOperationServiceImpl]: Constructor threw exception; nested exception is java.lang.UnsatisfiedLinkError: C:\Users\Administrator\AppData\Local\Temp\librocksdbjni15037951375079649142.dll: %
最新发布
07-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值