Class TimeZones


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

      Fields 
      Modifier and Type Field Description
      static java.util.TimeZone GMT
      The shared time zone representing Greenwich Mean Time (GMT).
      static java.lang.String GMT_ID
      The ID for indicating the GMT zone.
    • Constructor Summary

      Constructors 
      Constructor Description
      TimeZones()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.TimeZone getTimeZone​(int utcOffsetHours, int utcOffsetMinutes)
      Retrieves a time zone based upon a UTC offset days and minutes for the given date.
      static java.util.TimeZone getTimeZone​(java.util.Date date, int offset)
      Retrieves a time zone based upon a UTC offset for the given date.
      static java.util.TimeZone getTimeZone​(java.util.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 Detail

      • GMT_ID

        public static final java.lang.String GMT_ID
        The ID for indicating the GMT zone.
        See Also:
        Constant Field Values
      • GMT

        public static final java.util.TimeZone GMT
        The shared time zone representing Greenwich Mean Time (GMT).
    • Constructor Detail

      • TimeZones

        public TimeZones()
    • Method Detail

      • getTimeZone

        public static java.util.TimeZone getTimeZone​(java.util.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:
        java.lang.NullPointerException - if the given date is null.
        java.lang.IllegalArgumentException - if an offset was provided for which no time zone could be found.
      • getTimeZone

        public static java.util.TimeZone getTimeZone​(java.util.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:
        java.lang.NullPointerException - if the given date is null.
        java.lang.IllegalArgumentException - if an offset was provided for which no time zone could be found.
      • getTimeZone

        public static java.util.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:
        java.lang.IllegalArgumentException - if an offset was provided for which no time zone could be found.