Skip to content

Instantly share code, notes, and snippets.

@maikelsperandio
Created October 23, 2019 18:16
Show Gist options
  • Save maikelsperandio/66c7ef1bed202820d60901de45b6ecf1 to your computer and use it in GitHub Desktop.
Save maikelsperandio/66c7ef1bed202820d60901de45b6ecf1 to your computer and use it in GitHub Desktop.
List the timezone config in the jvm Daylight Saving Time database.
import java.util.Date;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.zone.ZoneOffsetTransition;
import java.time.zone.ZoneRules;
public class TimezoneList {
public static void main(String[] args) {
System.out.println(new Date());
ZoneId zone = ZoneId.of("America/Sao_Paulo");
ZoneRules rules = zone.getRules();
ZonedDateTime now = ZonedDateTime.now(zone);
ZoneOffsetTransition transition = rules.nextTransition(now.toInstant());
Instant max = now.plusYears(15).toInstant();
while (transition != null && transition.getInstant().isBefore(max)) {
System.out.println(transition);
transition = rules.nextTransition(transition.getInstant());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment