"EST" is one of the timeZone id from TimeZone.getAvailableIDs();
but
TimeZone.getAvailableIDs(); // contains EST
ZoneId.of("EST")
java.time.zone.ZoneRulesException: Unknown time-zone ID: EST
A ZoneId is used to identify the rules used to convert between an Instant and a LocalDateTime . There are two distinct types of ID: Fixed offsets - a fully resolved offset from UTC/Greenwich, that uses the same offset for all local date-times.
To find your zone and account IDs: Log in to the Cloudflare dashboard Open external link and select your account and domain. On the Overview page (the landing page for your domain), find the API section. The API section contains your Zone ID and Account ID.
Typically, you get a TimeZone using getDefault which creates a TimeZone based on the time zone where the program is running. For example, for a program running in Japan, getDefault creates a TimeZone object based on Japanese Standard Time. Hours must be between 0 to 23 and Minutes must be between 00 to 59.
The Time zone ID column lists time zones, in boldface, and the locations within each time zone. The Raw offset column lists the difference, in hours and minutes, between Greenwich Mean Time (GMT) and the specified time zone. The DST offset column lists the offset, in minutes, for Daylight Savings Time (DST).
Try this:
ZoneId.of("EST", ZoneId.SHORT_IDS);
Explanation: ZoneID.SHORT_IDS maps deprecated 3-letter codes to regular ones and for some reason it must be specified explicitely to take effect.
From JDK javadoc: "Use of short zone IDs has been deprecated in TimeZone".
You are mixing old and new API's.
TimeZone.getAvailableIDs()
returns Time Zone ID's that TimeZone.getTimeZone(String ID)
can resolve.
ZoneId.getAvailableZoneIds()
returns Zone ID's that ZoneId.of(String zoneId)
can resolve.
If you compare the results of the 2, you will see:
public static void main(String[] args) {
Set<String> timeZones = Set.of(TimeZone.getAvailableIDs());
Set<String> zoneIds = ZoneId.getAvailableZoneIds();
System.out.println("Extra TimeZone's: " + diff(timeZones, zoneIds));
System.out.println("Extra ZoneId's: " + diff(zoneIds, timeZones));
}
static Set<String> diff(Set<String> a, Set<String> b) {
Set<String> diff = new TreeSet<>(a);
diff.removeAll(b);
return diff;
}
Output (jdk-11.0.1)
Extra TimeZone's: [ACT, AET, AGT, ART, AST, BET, BST, CAT, CNT, CST, CTT, EAT, ECT, EST, HST, IET, IST, JST, MIT, MST, NET, NST, PLT, PNT, PRT, PST, SST, VST]
Extra ZoneId's: []
As you can see, ZoneId.getAvailableZoneIds()
does not claim to support EST
, only TimeZone.getAvailableIDs()
does.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With