Creating a TimeZone Object in Java

I am creating a Java TimeZone object using a TimeZone string such as GMT-8, GMT, PST, EST, etc. This did not take into account whether the time zone is enabled or not. Now there is a requirement to enable this check, and instead of entering as PDT or EDT, daylight saving time is set as a separate flag. I'm not sure if TimeZone has a direct method to change the DayLight property of saving this TimeZone.

So if I get inputs like PST and DaylightSaving as true, then I need to change the string as PDT. Which is even worse, sometimes I get inputs like GMT-8 or GMT-6 with the Day Day flag as true or false. Is there a way out?

I can not use third-party classes related to TimeZone

Code example:

TimeZone  timeZone = TimeZone.getTimeZone("EST");
TimeZone  timeZone = TimeZone.getTimeZone("PST");
TimeZone  timeZone = TimeZone.getTimeZone("GMT-8");
+3
source share
4 answers

I think that Java is supposed to by itself determine whether the time zone uses daylight saving or not, and when it is active.

Therefore, if you try to format a specific Date object with this time zone, the output should reflect daylight saving.

Whether this is reliable (given the frequent changes in this area), I do not know. You probably need to upgrade to the latest JVM to get the latest timezone database files (if you can't do this, there is a separate timezone update tool ).

+1
source

, "PST" "GMT-8", , . (, "PST" " " " ".)

, , TimeZone; : "/-".

ISO 8601.

, , .

, , ... , .. .

, , / , , , .

+3

, , , 3- , , JavaDoc. ,

JDK 1.1.x ( "PST", "CTT", "AST" ) . , (, "" . " " " " ), Java .

+2

"" TimeZone , . , Java.

TimeZone , , .. .

, TimeZone . Java .

TimeZone, SimpleTimeZone, , , . , ? , , . TimeZone.getAvailableIDs() TimeZone Java.

+1

Source: https://habr.com/ru/post/1781587/


All Articles