Class TimeZoneUtils


  • public final class TimeZoneUtils
    extends Object
    Simple utilities for working with TimeZones
    See Also:
    TimeZone
    • Field Detail

      • KNOWN_TIMEZONE_IDS

        public static final Set<String> KNOWN_TIMEZONE_IDS
        An immutable Set of all TimeZone IDs supported by the TimeZone class at the moment the TimeZoneUtils was initialized.
        See Also:
        TimeZone.getAvailableIDs(int)
    • Method Detail

      • getTimeZone

        public static final TimeZone getTimeZone​(String ID)
        This method is provided as a replacement for TimeZone.getTimeZone but without the annoying behavior of returning "GMT" for gibberish input.

        This method will return null unless the input is either:

        • Included in the set of known TimeZone IDs
        • A "CustomID" specified as a numeric offset from "GMT"
        Parameters:
        ID - Either a TimeZone ID found in KNOWN_TIMEZONE_IDS, or a "CustomID" specified as a GMT offset.
        Returns:
        A TimeZone object corresponding to the input, or null if no such TimeZone is supported.
        See Also:
        KNOWN_TIMEZONE_IDS, TimeZone
      • parseTimezone

        public static TimeZone parseTimezone​(String tzStr)
        Parse the specified timezone ID. If null input then return UTC. If we can't resolve it then throw an exception. Does not return null.