I have a string, I need to check whether it is a standard time zone identifier or not. I am not sure which method I need to use.
String timeZoneToCheck = "UTC";
I would like to check whether it represents a valid time zone or not.
I have a string, I need to check whether it is a standard time zone identifier or not. I am not sure which method I need to use.
String timeZoneToCheck = "UTC";
I would like to check whether it represents a valid time zone or not.
I would like to propose the next workaround:
As result in case of invalid timezone ID or invalid just custom timezone you will receive null. Additionally you can introduce corresponding null value handler (use case dependent) - throw exception & etc.
If
TimeZone.getAvailableIDs()
contains ID in question, it's valid:Unfortunately
TimeZone.getTimeZone()
method silently discards invalid IDs and returns GMT instead: