Java Time: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 17: Line 17:


==Daylight Saving Time Offset==
==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.
<pre>
TimeZone tz = ...
tz.getDSTSavings();
</pre>
The method implementation checks for whether the daylight savings time is in effect and returns 1 hour or 0:
<pre>
public int getDSTSavings() {
    if (useDaylightTime()) {
        return 3600000;
    }
    return 0;
}
</pre>


==Figuring Out Whether Daylight Saving is in Effect for a Certain Date==
==Figuring Out Whether Daylight Saving is in Effect for a Certain Date==

Revision as of 22:02, 13 July 2016

Internal

Time Zone

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);