I would like to know if the following is DST aware ie., the SimpleDateFormat parse method is DST aware if we set the Timezone of that respective country.
SimpleDateFormat sdf = new SimpleDateFormat();
sdf.setTimeZone(TimeZone.getTimeZone("CET")); //Germany
String currentDate = sdf.format((new Date()).getTime());
currentDate = sdf.parse(currentDate);
I undserstand that "CET", "MST", "EST" etc are three letter codes and is not encouraged to use this, but irrespective of this is the dateformat parse DST aware ?
Thanks in advance.
In some specific cases, the three-letter codes will work - but not all of them include daylight saving time rules.
From the TZ database sources:
Europe:
# Zone NAME GMTOFF RULES FORMAT [UNTIL]
Zone WET 0:00 EU WE%sT
Zone CET 1:00 C-Eur CE%sT
Zone MET 1:00 C-Eur ME%sT
Zone EET 2:00 EU EE%sT
North America:
# Zone NAME GMTOFF RULES FORMAT [UNTIL]
Zone EST -5:00 - EST
Zone MST -7:00 - MST
Zone HST -10:00 - HST
As you can see, the European file defines 4 three-letter zones for backwards compatibility purposes, all of which follow European daylight saving time rules.
However, the North American file only defines 3 of these. Notably, PST and CST are missing. Also, the EST and MST zones that are defined do not have any daylight saving time rules.
In general, you should avoid using the three-letter abbreviations. They are not all supported, the ones that are do not all support DST, and in general they can be ambiguous.
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