Java Time: Difference between revisions
Line 4: | Line 4: | ||
=Time Zone= | =Time Zone= | ||
The JVM obtains the default time zone from the system. For more details, see [[Time#Time_Zone|time zone]]. If JVM fails to identify the time zone set externally, it defaults to GMT. | |||
The default time zone in the JVM can be obtained by the Java programs with the following API: | |||
<pre> | |||
TimeZone dt = TimeZone.getDefault(); | |||
</pre> | |||
The timezone instance can be queried for its standard name ("Eastern Standard Time") and ID ("America/New_York"). | |||
==Raw Time Zone Offset== | ==Raw Time Zone Offset== |
Revision as of 22:03, 13 July 2016
Internal
Time Zone
The JVM obtains the default time zone from the system. For more details, see time zone. If JVM fails to identify the time zone set externally, it defaults to GMT.
The default time zone in the JVM can be obtained by the Java programs with the following API:
TimeZone dt = TimeZone.getDefault();
The timezone instance can be queried for its standard name ("Eastern Standard Time") and ID ("America/New_York").
Raw Time Zone Offset
We can get the amount of milliseconds to apply to UTC to get the standard time in a certain time zone (the standard time offset) with TimeZone.getRawOffset().
This value is not affected by daylight saving time.
TimeZone tz = ... tz.getRawOffset()
Daylight Saving Time Offset
We can get the amount of time to be added to local standard time to get local wall clock time correctly adjusted for daylight time saving.
TimeZone tz = ... tz.getDSTSavings();
The method implementation checks for whether the daylight savings time is in effect and returns 1 hour or 0:
public int getDSTSavings() { if (useDaylightTime()) { return 3600000; } return 0; }
Figuring Out Whether Daylight Saving is in Effect for a Certain Date
Date d = ... inDaylightTime(d);