Class TimeZones

java.lang.Object
com.globalmentor.time.TimeZones

public class TimeZones extends Object
Constant values and utilities for working with time zones.
Author:
Garret Wilson
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final TimeZone
    The shared time zone representing Greenwich Mean Time (GMT).
    static final String
    The ID for indicating the GMT zone.
    static final TimeZone
    The shared time zone representing Coordinated Universal Time (UTC).
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static TimeZone
    getTimeZone(int utcOffsetHours, int utcOffsetMinutes)
    Retrieves a time zone based upon a UTC offset days and minutes for the given date.
    static TimeZone
    getTimeZone(Date date, int offset)
    Retrieves a time zone based upon a UTC offset for the given date.
    static TimeZone
    getTimeZone(Date date, int utcOffsetHours, int utcOffsetMinutes)
    Retrieves a time zone based upon a UTC offset days and minutes for the given date.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • GMT_ID

      public static final String GMT_ID
      The ID for indicating the GMT zone.
      API Note:
      The GMT designation has been superseded by UTC, but its ID is still used by the TimeZone class.
      See Also:
    • GMT

      public static final TimeZone GMT
      The shared time zone representing Greenwich Mean Time (GMT).
      API Note:
      Modern time processing should use UTC instead.
    • UTC

      public static final TimeZone UTC
      The shared time zone representing Coordinated Universal Time (UTC).
      API Note:
      This time zone is equivalent to ZoneOffset.UTC.
  • Constructor Details

    • TimeZones

      public TimeZones()
  • Method Details

    • getTimeZone

      public static TimeZone getTimeZone(Date date, int offset)
      Retrieves a time zone based upon a UTC offset for the given date. This method cannot return with certain a time zone valid for other dates, as sufficient information both as to location and to daylight saving is not provided. This method cannot handle offsets that do not fall on whole minutes.
      Parameters:
      date - The date for which a time zone will be calculated.
      offset - The UTC offset for which a time zone will be retrieved, in milliseconds.
      Returns:
      A time zone appropriate for the given UTC offset for the given date.
      Throws:
      NullPointerException - if the given date is null.
      IllegalArgumentException - if an offset was provided for which no time zone could be found.
    • getTimeZone

      public static TimeZone getTimeZone(Date date, int utcOffsetHours, int utcOffsetMinutes)
      Retrieves a time zone based upon a UTC offset days and minutes for the given date. This method cannot return with certain a time zone valid for other dates, as sufficient information both as to location and to daylight saving is not provided.
      Parameters:
      date - The date for which a time zone will be calculated.
      utcOffsetHours - The UTC offset hours.
      utcOffsetMinutes - The UTC offset minutes, or -1 if there is no UTC offset hours or minutes specified.
      Returns:
      A time zone appropriate for the given UTC offset for the given date.
      Throws:
      NullPointerException - if the given date is null.
      IllegalArgumentException - if an offset was provided for which no time zone could be found.
    • getTimeZone

      public static TimeZone getTimeZone(int utcOffsetHours, int utcOffsetMinutes)
      Retrieves a time zone based upon a UTC offset days and minutes for the given date. This method cannot return with certain a time zone valid for other dates, as sufficient information both as to location and to daylight saving is not provided.
      Parameters:
      utcOffsetHours - The UTC offset hours.
      utcOffsetMinutes - The UTC offset minutes, or -1 if there is no UTC offset hours or minutes specified.
      Returns:
      A general time zone appropriate for the given UTC offset.
      Throws:
      IllegalArgumentException - if an offset was provided for which no time zone could be found.