TimeZone Class

Represents a time zone. Contains methods for creating a new time zone and obtaining time zone properties, such as the time zone ID, offset, and display name.

System

You can use the methods in this class to get properties of a time zone, such as the properties of the time zone returned by UserInfo.getTimeZone, or the time zone returned by getTimeZone of this class.

This example shows how to get properties of the current user’s time zone and display them to the debug log. The output of the sample varies based on the user’s time zone.

This second example shows how to create a time zone for the New York time zone and get the offset of this time zone to the GMT time zone. The example uses two dates to get the offset from. One date is before DST (Daylight Saving Time), and one is after DST. In 2000, DST ended on Sunday, October 29 for the New York time zone. Because the date occurs after DST ends, the offset on the first date is –5 hours to GMT. In 2012, DST ended on Sunday, November 4. Because the date is within DST, the offset on the second date is –4 hours.

This next example is similar to the previous one except that it gets the offset around the boundary of DST. In 2014, DST ended on Sunday, November 2 at 2:00 AM local time for the New York time zone. The first offset is obtained right before DST ends, and the second offset is obtained right after DST ends. The dates are created by using the DateTime.newInstanceGMT method. This method expects the passed-in date values to be based on the GMT time zone.

The following are methods for TimeZone.

Returns this time zone’s display name.

public String getDisplayName()

Type: String

In API version 45.0 and later, getDisplayName displays Daylight Savings Time appropriately when daylight savings are in effect. For example, British Summer Time is displayed for Europe/London and Pacific Daylight Time for America/Los_Angeles.

Returns this time zone’s ID.

public String getID()

Type: String

Returns the time zone offset, in milliseconds, of the specified date to the GMT time zone.

public Integer getOffset(Datetime date)

  • date: Type: Datetime The date argument is the date and time to evaluate.

Type: Integer

The returned offset is adjusted for daylight saving time if the date argument falls within daylight saving time for this time zone.

Returns the time zone corresponding to the specified time zone ID.

public static TimeZone getTimeZone(String timeZoneIdString)

  • timeZoneIdString: Type: String The time zone values you can use for the Id argument are any valid time zone values that the Java TimeZone class supports.

Type: TimeZone

Returns the string representation of this time zone.

public String toString()

Type: String