Is there any function in joda.time which validates a string whether it represents correct time zone or not and throws a exception if it is not in the correct format?
I am aware of TimeZone.getAvalibaleIDs() but just curious to know if there is any predefined function.
DateTimeZone.forID()will throw an exception if the ID isn’t recognized.That’s appropriate if you’re trying to get the actual zone – if you’re just trying to validate whether an ID is valid or not, I’d use
getAvailableIDs():That’s better in terms of avoiding using exceptions for flow control, IMO. However, they’re not equivalent – fixed-offset time zone IDs are valid in
DateTimeZone.forID(), but may not be included in the set of available IDs.