Apex provides a TimeZone API. You can use this to query the detail of a time zone, named using its "SID" (a value like "Europe/London" or "America/New_York" for example). However, this API doesn't provide a means to query the SIDs for the supported time zones.

How can I determine the valid set of supported time zones by SID?


If you call TimeZone.getTimeZone with an invalid SID you get back the "GMT" time zone instance - this is one way to validate that your SID is supported (by checking that the SID for the object you get back is the same as the SID you provided). However, that doesn't help with getting the list of valid options.

Fortunately, the Salesforce schema includes a field on User, TimeZoneSidKey, that is a picklist containing all the valid SID values. This can be queried in Apex thus:

List<PicklistEntry> entries = Schema.SObjectType.User.fields.TimeZoneSidKey.picklistValues;

Each entry contains a single SID, which is the actual "value" for the entry.

  • 4
    FYI you can drop the Schema. in most cases, including this one. – Adrian Larson Mar 18 at 16:29
  • 1
    User.TimeZoneSidKey.getDescribe().picklistValues also works – cropredy Mar 18 at 16:58
  • Look at all that typing you guys could have saved me ;) – Phil W Mar 18 at 17:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.