1 Reply Latest reply: Oct 21, 2009 11:43 AM by DrClap RSS

    TimeZone ID validation

      java.util.TimeZone.getTimeZone(id) method takes a String parameter that is called timeZoneID.
      As per the method comments it will return GMT if given id can not be understood.

      My question is, Does Java provide any method to validate the timeZone ID that is to be supplied to this method. Or is there any other method available which return null or throws exception if timeZone ID can not be understood instead of returning GMT timeZone.

      I don't want to write my own validation method which checks the given id against TimeZone.getAvailableIDs() as id can be a customized ID like GMT+8, GMT+05:30 or UTC+1 etc. and for correect handling of all such cases I have to add number of ifs and else in the method.

      What I am looking for is a full proof method for validating the timeZoneID.
        • 1. Re: TimeZone ID validation
          A quick look at the API documentation reveals that TimeZone.getAvailableIDs() returns an array of the valid time zone IDs. You could write a little bit of code which checks that your string is in that array of strings.