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.
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.