java unsupport_java-UnsupportedTemporalTypeException:不支持的字...

我有这段代码正在生成一个时间戳,然后解析.

DateTimeFormatter formatter =

DateTimeFormatter

.ofPattern("yyyyMMdd kk:HH:ss.SSSZ")

.withLocale(Locale.getDefault())

.withZone(ZoneId.systemDefault());

Instant now = Instant.now();

String formatted = formatter.format(now);

Instant parsed = formatter.parse(formatted, Instant::from);

运行时,最后一行会产生异常:

java.time.format.DateTimeParseException: Text '20180123 12:12:45.648-0500' could not be parsed: Unable to obtain Instant from TemporalAccessor: {SecondOfMinute=45, NanoOfSecond=648000000, OffsetSeconds=-18000, MilliOfSecond=648, MicroOfSecond=648000, HourOfDay=12},ISO,America/New_York resolved to 2018-01-23 of type java.time.format.Parsed

Caused by: java.time.DateTimeException: Unable to obtain Instant from TemporalAccessor: {SecondOfMinute=45, NanoOfSecond=648000000, OffsetSeconds=-18000, MilliOfSecond=648, MicroOfSecond=648000, HourOfDay=12},ISO,America/New_York resolved to 2018-01-23 of type java.time.format.Parsed

Caused by: java.time.temporal.UnsupportedTemporalTypeException: **Unsupported field: InstantSeconds**

我用DateTimeFormatter.ISO_INSTANT替换了格式化程序,它可以正常工作.产生的实际数据几乎相同.什么是断开连接?

ISO_INSTANT: 2018-01-23T16:51:25.516Z

My Format: 20180119 23:59:59.999-0800

我必须使用我的格式.这里有什么问题?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值