我正在尝试22/04/17 09:24:28 UTC+01使用格式进行解析dd/MM/yy HH:mm:ss zX- 但无论偏移量如何,创建的 ZonedDateTime 都是相同的。
下面是一个重现此示例的示例,我在其中以编程方式更改偏移量:
final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yy HH:mm:ss zX")
.withZone(ZoneId.systemDefault());
System.out.println(MessageFormat.format("Current time is \"{0}\"", formatter.format(Instant.now())));
for (int i = 1; i <= 12; i++) {
final String str = String.format("22/04/17 09:24:28 UTC+%02d", i);
System.out.println(MessageFormat.format("Parsed String \"{0}\", got result of \"{1}\"", str,
ZonedDateTime.parse(str, formatter)));
}
输出:
Current time is "12/07/19 12:59:25 ZZ"
Parsed String "22/04/17 09:24:28 UTC+01", got result of "2017-04-22T09:24:28Z[UTC]"
Parsed String "22/04/17 09:24:28 UTC+02", got result of "2017-04-22T09:24:28Z[UTC]"
Parsed String "22/04/17 09:24:28 UTC+03", got result of "2017-04-22T09:24:28Z[UTC]"
Parsed String "22/04/17 09:24:28 UTC+04", got result of "2017-04-22T09:24:28Z[UTC]"
Parsed String "22/04/17 09:24:28 UTC+05", got result of "2017-04-22T09:24:28Z[UTC]"
Parsed String "22/04/17 09:24:28 UTC+06", got result of "2017-04-22T09:24:28Z[UTC]"
Parsed String "22/04/17 09:24:28 UTC+07", got result of "2017-04-22T09:24:28Z[UTC]"
Parsed String "22/04/17 09:24:28 UTC+08", got result of "2017-04-22T09:24:28Z[UTC]"
Parsed String "22/04/17 09:24:28 UTC+09", got result of "2017-04-22T09:24:28Z[UTC]"
Parsed String "22/04/17 09:24:28 UTC+10", got result of "2017-04-22T09:24:28Z[UTC]"
Parsed String "22/04/17 09:24:28 UTC+11", got result of "2017-04-22T09:24:28Z[UTC]"
Parsed String "22/04/17 09:24:28 UTC+12", got result of "2017-04-22T09:24:28Z[UTC]"
请注意,无论偏移量如何,结果都是相同的。
偶然的你
相关分类