interface SomeDataClass {
  TemporalAccessor getSomeTime();
}

//somewhere in the impl...
public TemporalAccessor getSomeTime() {
  return OffsetDateTime.from(dateTimeFormatter.parse(someDateInstring));
}


有人知道如何从此TemporalAccessor界面获取时区数据吗?

最佳答案

如果需要ZoneOffsetZoneId,则可以从TemporalAccessor创建它:

TemporalAccessor acc = ZonedDateTime.now();
System.out.println(ZoneOffset.from(acc));
System.out.println(ZoneId.from(acc));

10-06 08:44