Dawid Pura
Dawid Pura

Reputation: 1029

How to get TimeZone from Temporal?

interface SomeDataClass {
  TemporalAccessor getSomeTime();
}

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

Does anyone know how to get timezone data from this TemporalAccessor interface?

Upvotes: 1

Views: 1602

Answers (1)

Tagir Valeev
Tagir Valeev

Reputation: 100279

If you need the ZoneOffset or ZoneId, you can create it from the TemporalAccessor:

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

Upvotes: 5

Related Questions