這裏是非常一切看上去就像一個ISO字符串匹配日期的最終格局!
"[yyyyMMdd][yyyy-MM-dd][yyyy-DDD]['T'[HHmmss][HHmm][HH:mm:ss][HH:mm][.SSSSSSSSS][.SSSSSS][.SSS][.SS][.S]][OOOO][O][z][XXXXX][XXXX]['['VV']']"
它適用於中除了兩個意見,但測試下面的列表中我還是不知道爲什麼...
ZonedDateTime dt = DateTimeUtils.parse("2016-10-27T16:36:08.993+02:00:00[Europe/Paris]");
dt = DateTimeUtils.parse("2016-10-27T16:36:08.993+02:00[Europe/Paris]");
dt = DateTimeUtils.parse("2016-10-27T16:36:08.993+020000[Europe/Paris]");
dt = DateTimeUtils.parse("2016-10-27T16:36:08.993+0200[Europe/Paris]");
dt = DateTimeUtils.parse("2016-10-27T16:36:08.993+0000[Europe/Paris]");
dt = DateTimeUtils.parse("2016-10-27T16:36:08.993Z[Europe/Paris]");
dt = DateTimeUtils.parse("2016-10-27T16:36:08.993GMT+1[Europe/Paris]");
dt = DateTimeUtils.parse("2016-10-27T16:36:08.993UTC[Europe/Paris]");
dt = DateTimeUtils.parse("2016-10-27T16:36:08.993PST[Europe/Paris]");
dt = DateTimeUtils.parse("2016-10-27T16:36:08.993[Europe/Paris]");
dt = DateTimeUtils.parse("2016-10-27T16:36:08+02:00[Europe/Paris]");
dt = DateTimeUtils.parse("2016-10-27T16:36:08+020000[Europe/Paris]");
dt = DateTimeUtils.parse("2016-10-27T16:36:08+0200[Europe/Paris]");
dt = DateTimeUtils.parse("2016-10-27T16:36:08+0000[Europe/Paris]");
dt = DateTimeUtils.parse("2016-10-27T16:36:08Z[Europe/Paris]");
dt = DateTimeUtils.parse("2016-10-27T16:36:08GMT+1[Europe/Paris]");
dt = DateTimeUtils.parse("2016-10-27T16:36:08UTC[Europe/Paris]");
dt = DateTimeUtils.parse("2016-10-27T16:36:08PST[Europe/Paris]");
dt = DateTimeUtils.parse("2016-10-27T16:36:08[Europe/Paris]");
dt = DateTimeUtils.parse("2016-10-27T16:36:08.993+02:00:00");
dt = DateTimeUtils.parse("2016-10-27T16:36:08.993+02:00");
dt = DateTimeUtils.parse("2016-10-27T16:36:08.993+020000");
dt = DateTimeUtils.parse("2016-10-27T16:36:08.993+0200");
dt = DateTimeUtils.parse("2016-10-27T16:36:08.993+0000");
dt = DateTimeUtils.parse("2016-10-27T16:36:08.993Z");
//dt = DateTimeUtils.parse("2016-10-27T16:36:08.993GMT+1");
dt = DateTimeUtils.parse("2016-10-27T16:36:08.993UTC");
dt = DateTimeUtils.parse("2016-10-27T16:36:08.993PST");
dt = DateTimeUtils.parse("2016-10-27T16:36:08.993");
dt = DateTimeUtils.parse("2016-10-27T16:36:08.000993");
dt = DateTimeUtils.parse("2016-10-27T16:36:08.000000993");
dt = DateTimeUtils.parse("2016-10-27T16:36:08+02:00:00");
dt = DateTimeUtils.parse("2016-10-27T16:36:08+02:00");
dt = DateTimeUtils.parse("2016-10-27T16:36:08+020000");
dt = DateTimeUtils.parse("2016-10-27T16:36:08+0200");
dt = DateTimeUtils.parse("2016-10-27T16:36:08+0000");
dt = DateTimeUtils.parse("2016-10-27T16:36:08Z");
//dt = DateTimeUtils.parse("2016-10-27T16:36:08GMT+1");
dt = DateTimeUtils.parse("2016-10-27T16:36:08UTC");
dt = DateTimeUtils.parse("2016-10-27T16:36:08PST");
dt = DateTimeUtils.parse("2016-10-27T16:36:08");
dt = DateTimeUtils.parse("2016-100T16:36:08Z");
dt = DateTimeUtils.parse("2016-100T16:36.1Z");
dt = DateTimeUtils.parse("2016-10-27");
dt = DateTimeUtils.parse("20161223T163608");
dt = DateTimeUtils.parse("20161223T1636");
與解析方法本身:
public static ZonedDateTime parse(CharSequence text) {
TemporalAccessor temporalAccessor = LOOSE_ISO_DATE_TIME_ZONE_PARSER.parseBest(text, ZonedDateTime::from, LocalDateTime::from, LocalDate::from);
if (temporalAccessor instanceof ZonedDateTime) {
return ((ZonedDateTime) temporalAccessor);
}
if (temporalAccessor instanceof LocalDateTime) {
return ((LocalDateTime) temporalAccessor).atZone(ZoneId.systemDefault());
}
return ((LocalDate) temporalAccessor).atStartOfDay(ZoneId.systemDefault());
}
您認爲可選的冒號是區域偏移量部分的固定部分。您只能選擇模式字母X(不含冒號)或XXX(含冒號)。這意味着整個區域偏移量是可選的,而不僅僅是內部的冒號。 –
我同意,它應該工作。但是,當我使用[X]時,它預計沒有冒號的偏移量,當我使用[XXX]時,它期望有冒號的偏移量。我不能一起使用兩者。 –
根據Javadoc:用符號X給出這些例子:Z; -08; -0830; -08:30; -083015; -08:30:15; –