加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 如何创建一个包含ZERO时区的新LocalDateTime?

发布时间:2020-12-15 04:24:07 所属栏目:Java 来源:网络整理
导读:new LocalDateTime(“1999-12-31T00:00:00Z”); 当我尝试创建此日期时,我得到: Exception in thread "main" java.lang.IllegalArgumentException: Invalid format: "1999-12-31T00:00:00Z" is malformed at "Z" at org.joda.time.format.DateTimeParserBu
new LocalDateTime(“1999-12-31T00:00:00Z”);

当我尝试创建此日期时,我得到:

Exception in thread "main" java.lang.IllegalArgumentException: Invalid format: "1999-12-31T00:00:00Z" is malformed at "Z"
    at org.joda.time.format.DateTimeParserBucket.doParseMillis(DateTimeParserBucket.java:187)
    at org.joda.time.format.DateTimeFormatter.parseMillis(DateTimeFormatter.java:780)
    at org.joda.time.convert.StringConverter.getPartialValues(StringConverter.java:87)
    at org.joda.time.LocalDateTime.<init>(LocalDateTime.java:414)
    at org.joda.time.LocalDateTime.<init>(LocalDateTime.java:358)

我怎样才能将该日期解析为LocalDateTime?

解决方法

How can I then parse that date to LocalDateTime?

你不能 – LocalDateTime表示根本没有相关时区的日期和时间.如果您有一个锚定到时区的时间戳(在本例中为UTC),那么您应该使用DateTime而不是LocalDateTime.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读