Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correct ZoneId for eastern time (ET): either "US/Eastern" or "America/New_York"?

Tags:

java

timezone

I have to use the time zone "ET" (Eastern Time). In Java, there is no ZoneId.of("ET").

Which one should I use to represent the "ET" correctly:

ZoneId TIMEZONE_ET = ZoneId.of("US/Eastern");

or

ZoneId TIMEZONE_ET = ZoneId.of("America/New_York");
like image 342
nimo23 Avatar asked Jun 25 '19 16:06

nimo23


2 Answers

Given that your requirement is to use the "Eastern zone," I'd use US/Eastern, but note:

  • It's just a link to America/New_York.
  • This file in Paul Eggert's tz repo says those links are to link "old" names (such as US/Eastern) to current names. "Old" may well mean "deprecated" in this context. Paul Eggert is the TZ Coordinator for IANA's Time Zone list, so this is a clearly canonical source.

Given that, you're probably best off with America/New_York, but given that the change is listed as being from 1993, clearly the old names aren't going away any time soon.

Either will contain the DST rules, etc. On my system, for instance:

var zoneRules = ZoneId.of("US/Eastern").getRules();
System.out.println(zoneRules.isDaylightSavings(Instant.parse("2019-07-01T12:00:00Z"))); // true
System.out.println(zoneRules.isDaylightSavings(Instant.parse("2019-01-01T12:00:00Z"))); // false

Note that noon on July 1st is in DST, and noon on January 1st is not.

More:

In the IANA Time Zone Database files, I've found:

to2050.tzs:

Link America/New_York    US/Eastern

...which suggests the two are aliases (altough ZoneId#equals doesn't return true for them). Also, in northamerica they have:

# US eastern time, represented by New York

with notes citing the relevant law.

So it seems clear to me that at the moment, they're synonymous. It's also clear that US/Eastern is the "old name." Of course, in theory, New York could decide at some point not to be part of the Eastern timezone anymore (perhaps to be closer, time-wise, to the UK and Europe), but that seems really unlikely...

like image 184
T.J. Crowder Avatar answered Sep 21 '22 04:09

T.J. Crowder


America/New_York

The answer is in the List of tz database time zones: US/Eastern is deprecated and is just a link to America/New_York. So to be sure of future compatibility you should use America/New_York.

Wikipedia on the names of time zones

The Wikipedia article tz database says (excerpts):

The time zones have unique names in the form "Area/Location", e.g. "America/New_York". …

Area is the name of a continent, an ocean, or "Etc". The continents and oceans currently used are Africa, America, Antarctica, Arctic, Asia, Atlantic, Australia, Europe, Indian, and Pacific.

Location is the name of a specific location within the area – usually a city or small island.

Country names are not used in this scheme, primarily because they would not be robust, owing to frequent political and boundary changes. The names of large cities tend to be more permanent. …

So the name US/Eastern is from a time when names were created following other rules.

About the abbreviation, ET

Since I sensed a doubt in a couple of the comments: North American Eastern Time may be and is commonly abbreviated ET. One way to see this is in the Time Zone Abbreviations – Worldwide List. You can also see that ET may either comprise both EST (Eastern Standard Time) and EDT (Eastern Daylight Time) or be used as a synonym for EST, also known as Tiempo del Este in Spanish. When you study the list, you will also see that very many abbreviations are ambiguous.

Or in Java (using REPL):

jshell> ZoneId.of("America/New_York").getDisplayName(TextStyle.SHORT, Locale.US) 
$3 ==> "ET"

Just out of curiosity and not recommended because of the risk of ambiguity: you may also go the other way and obtain the ZoneId from the abbreviation:

jshell> var dtf = DateTimeFormatter.ofPattern("z", Locale.US);
dtf ==> ZoneText(SHORT)

jshell> ZoneId.from(dtf.parse("ET"))
$7 ==> America/New_York

I repeat: don’t try this last trick at home.

like image 39
Ole V.V. Avatar answered Sep 20 '22 04:09

Ole V.V.