【发布时间】:2020-01-08 21:49:15
【问题描述】:
Joda ISODateTimeFormat 文档说 ISODateTimeFormat.dateTime() 返回模式 yyyy-MM-dd'T'HH:mm:ss.SSSZZ
但格式化程序返回一个“Z”代替 +00:00
看到这个-
DateTime dt = DateTime.now(DateTimeZone.UTC);
DateTimeFormatter patternFormat = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZZ");
DateTimeFormatter isoFormat = ISODateTimeFormat.dateTime();
System.out.println(dt.toString(patternFormat)); //2014-06-01T03:02:13.552+00:00
System.out.println(dt.toString(isoFormat)); //2014-06-01T03:02:13.552Z
谁能告诉我将 +00:00 打印为 Z 的模式是什么
编辑: 只是为了澄清一下-我知道“Z”与 +00:00 相同,但在文本上它是不同的。我要问的是什么模式会将 Z 作为时间偏移而不是 +00:00
(对不起,如果这太琐碎了。我想在没有毫秒的情况下使用 ISO 格式,在写这个问题的过程中,我在ISODateTimeFormat.dateTimeNoMillis() 中找到了我所追求的东西,所以我现在只问兴趣清酒)
【问题讨论】:
-
这个问题似乎被误解了。我认为问题是:为什么偏移量为零 (+00:00) 的 Joda-Time 日期时间值有时会生成以
Z结尾的字符串,有时会以+00:00结尾?如何指定一个结尾而不是另一个结尾?