Java Time

From NovaOrdis Knowledge Base
Jump to navigation Jump to search

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