本文介绍了DateTimeFormatter解析所有ISO有效的区域偏移样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用以下格式化程序,我可以解析"2017-03-28T23:40:06.000+0100"
With the following formatter I'm able to parse "2017-03-28T23:40:06.000+0100"
new DateTimeFormatterBuilder()
.append(ISO_LOCAL_DATE_TIME)
.appendPattern("X")
.toFormatter();
与另一个解析"2017-03-28T23:40:06.000+01:00"
new DateTimeFormatterBuilder()
.append(ISO_LOCAL_DATE_TIME)
.appendPattern("XX")
.toFormatter();
但是,我无法指定同时解析两者的格式化程序.我应该附加什么模式?
However, I'm unable to specify formatter that parses both. What pattern should I append?
Formatter还应该能够处理没有区域偏移的时间戳,例如"2017-03-28T23:40:06.000Z"
Formatter should also be able to process timestamps without zone-offset, e.g. "2017-03-28T23:40:06.000Z"
推荐答案
以下内容开始为我服务
new DateTimeFormatterBuilder()
.append(ISO_LOCAL_DATE_TIME)
.optionalStart()
.appendPattern("[XXX][X]")
.toFormatter();
这篇关于DateTimeFormatter解析所有ISO有效的区域偏移样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!