+ Start a Discussion
Naresh Krishna.ax1176Naresh Krishna.ax1176 

How to get the time zone value in salesforce

Hi All,

 

Using the below query we are able to get TimeZone:

 

SELECT ID, TimeZoneSidKey FROM User WHERE ID = :UserInfo.getUserId()

 

For example, on edit user detail, if we pick the Time zone as (GMT-08:00) Pacific Standard Time (America/Los_Angeles) from the pick list then the TimeZoneSidKey will be America/Los_Angeles.

 

Is there any method to get the TimeZoneSidKey's value i.e,  (GMT-08:00) Pacific Standard Time (America/Los_Angeles) ?


Thanks.



hisrinuhisrinu

Seems to be you can't get this information, however here is the workaround

 

http://www.force2b.net/index.php/2010/08/date-time-and-timezone-handling-in-apex/

Gagandeep-SinghGagandeep-Singh

Schema.DescribeFieldResult fieldResult = User.TimeZoneSidKey.getdescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
for(Schema.PicklistEntry p : ple)
{
system.debug('###'+p.getlabel()+'****'+p.getValue()+'\n');

}

DigitalDarwinDigitalDarwin

(GMT+14:00) Line Islands Time (Pacific/Kiritimati)
(GMT+13:45) Chatham Daylight Time (Pacific/Chatham)
(GMT+13:00) New Zealand Daylight Time (Pacific/Auckland)
(GMT+13:00) Phoenix Islands Time (Pacific/Enderbury)
(GMT+13:00) Fiji Summer Time (Pacific/Fiji)
(GMT+13:00) Tonga Time (Pacific/Tongatapu)
(GMT+12:00) Magadan Time (Asia/Kamchatka)
(GMT+11:30) Norfolk Islands Time (Pacific/Norfolk)*
(GMT+11:00) Lord Howe Daylight Time (Australia/Lord_Howe)
(GMT+11:00) Australian Eastern Daylight Time (Australia/Sydney)
(GMT+11:00) Solomon Islands Time (Pacific/Guadalcanal)
(GMT+10:30) Australian Central Daylight Time (Australia/Adelaide)
(GMT+09:30) Australian Central Standard Time (Australia/Darwin)
(GMT+09:00) Korean Standard Time (Asia/Seoul)
(GMT+09:00) Japan Standard Time (Asia/Tokyo)
(GMT+08:00) Hong Kong Time (Asia/Hong_Kong)
(GMT+08:00) Malaysia Time (Asia/Kuala_Lumpur)
(GMT+08:00) Philippine Time (Asia/Manila)
(GMT+08:00) China Standard Time (Asia/Shanghai)
(GMT+08:00) Singapore Standard Time (Asia/Singapore)
(GMT+08:00) Taipei Standard Time (Asia/Taipei)
(GMT+08:00) Australian Western Standard Time (Australia/Perth)
(GMT+07:00) Indochina Time (Asia/Bangkok)
(GMT+07:00) Indochina Time (Asia/Ho_Chi_Minh)
(GMT+07:00) Western Indonesia Time (Asia/Jakarta)
(GMT+06:30) Myanmar Time (Asia/Rangoon)
(GMT+06:00) Bangladesh Time (Asia/Dhaka)
(GMT+06:00) Yekaterinburg Time (Asia/Yekaterinburg)
(GMT+05:45) Nepal Time (Asia/Kathmandu)
(GMT+05:30) India Standard Time (Asia/Colombo)
(GMT+05:30) India Standard Time (Asia/Kolkata)
(GMT+05:00) Pakistan Time (Asia/Karachi)
(GMT+05:00) Uzbekistan Time (Asia/Tashkent)
(GMT+04:30) Afghanistan Time (Asia/Kabul)
(GMT+04:00) Gulf Standard Time (Asia/Dubai)
(GMT+04:00) Georgia Time (Asia/Tbilisi)
(GMT+04:00) Moscow Standard Time (Europe/Moscow)
(GMT+03:30) Iran Standard Time (Asia/Tehran)
(GMT+03:00) East Africa Time (Africa/Nairobi)
(GMT+03:00) Arabian Standard Time (Asia/Baghdad)
(GMT+03:00) Arabian Standard Time (Asia/Kuwait)
(GMT+03:00) Arabian Standard Time (Asia/Riyadh)
(GMT+03:00) Further-eastern European Time (Europe/Minsk)
(GMT+02:00) Eastern European Time (Africa/Cairo)
(GMT+02:00) South Africa Standard Time (Africa/Johannesburg)
(GMT+02:00) Israel Standard Time (Asia/Jerusalem)
(GMT+02:00) Eastern European Time (Europe/Athens)
(GMT+02:00) Eastern European Time (Europe/Bucharest)
(GMT+02:00) Eastern European Time (Europe/Helsinki)
(GMT+02:00) Eastern European Time (Europe/Istanbul)
(GMT+01:00) Central European Time (Africa/Algiers)
(GMT+01:00) Central European Time (Europe/Amsterdam)
(GMT+01:00) Central European Time (Europe/Berlin)
(GMT+01:00) Central European Time (Europe/Brussels)
(GMT+01:00) Central European Time (Europe/Paris)
(GMT+01:00) Central European Time (Europe/Prague)
(GMT+01:00) Central European Time (Europe/Rome)
(GMT+00:00) Greenwich Mean Time (Europe/Dublin)
(GMT+00:00) Western European Time (Europe/Lisbon)
(GMT+00:00) Greenwich Mean Time (Europe/London)
(GMT+00:00) Greenwich Mean Time (GMT)
(GMT-01:00) Cape Verde Time (Atlantic/Cape_Verde)
(GMT-02:00) Brasilia Summer Time (America/Sao_Paulo)
(GMT-02:00) South Georgia Time (Atlantic/South_Georgia)
(GMT-03:00) Argentina Time (America/Argentina/Buenos_Aires)
(GMT-03:00) Chile Summer Time (America/Santiago)
(GMT-03:30) Newfoundland Standard Time (America/St_Johns)
(GMT-04:00) Atlantic Standard Time (America/Halifax)
(GMT-04:00) Atlantic Standard Time (America/Puerto_Rico)
(GMT-04:00) Atlantic Standard Time (Atlantic/Bermuda)
(GMT-04:30) Venezuela Time (America/Caracas)
(GMT-05:00) Colombia Time (America/Bogota)
(GMT-05:00) Eastern Standard Time (America/Indiana/Indianapolis)
(GMT-05:00) Peru Time (America/Lima)
(GMT-05:00) Eastern Standard Time (America/New_York)
(GMT-05:00) Eastern Standard Time (America/Panama)
(GMT-06:00) Central Standard Time (America/Chicago)
(GMT-06:00) Central Standard Time (America/El_Salvador)
(GMT-06:00) Central Standard Time (America/Mexico_City)
(GMT-07:00) Mountain Standard Time (America/Denver)****America/Denver
(GMT-07:00) Mountain Standard Time (America/Phoenix)
(GMT-08:00) Pacific Standard Time (America/Los_Angeles)
(GMT-08:00) Pacific Standard Time (America/Tijuana)
(GMT-09:00) Alaska Standard Time (America/Anchorage)
(GMT-10:00) Hawaii-Aleutian Standard Time (Pacific/Honolulu)
(GMT-11:00) Niue Time (Pacific/Niue)
(GMT-11:00) Samoa Standard Time (Pacific/Pago_Pago)

Stephen SpragueStephen Sprague
Gagandeep-Singh, DigitalDarwin -- The list will be incomplete dependant on what day you run that snip of code.  For Example, I know DigitalDarwin's list was obtained during Eastern Standard Time (NY) because there is no Eastern Daylight Time (NY) (one is offset differently based on DST, although at essentially the UI level).  This would have to be ran during all  the different supported DST times in order to get a complete / 100% accurate list.  I merged Wiki's timezone list here (https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) or https://en.wikipedia.org/wiki/List_of_tz_database_time_zones and SFDCs timezone list here (https://help.salesforce.com/apex/HTViewHelpDoc?id=admin_supported_timezone.htm) or https://help.salesforce.com/apex/HTViewHelpDoc?id=admin_supported_timezone.htm to get the following list of timezones w/ a boolean to determine if DST is supported or not based on UTC / UTC - DST difference.

If you copy the code into notepad, then save it as a .csv, Excel or the like should open it separated into columns as intended.

NOTE: The Time Zone Code column, found in the H&T Doc linked above, would be inaccurate for any DST affected TZ depending on the time of year.  The Time Zone Code SFDC column is the timezonesidkey which would be found on the user record.

Complete list of salesforce time zones with daylight savings time ( DST ) offsets for each based on TimeZoneSidKey / Wiki / H&T.
Time Zone Code SFDC,UTC,UTC-DST,DST?,Time Zone Code,Time Zone Name
Pacific/Kiritimati,+14:00,+14:00,False,GMT+14:00,Line Is. Time (Pacific/Kiritimati)
Pacific/Enderbury,+13:00,+13:00,False,GMT+13:00,Phoenix Is.Time (Pacific/Enderbury)
Pacific/Tongatapu,+13:00,+13:00,False,GMT+13:00,Tonga Time (Pacific/Tongatapu)
Pacific/Chatham,+12:45,+13:45,True,GMT+12:45,Chatham Standard Time (Pacific/Chatham)
Pacific/Auckland,+12:00,+13:00,True,GMT+12:00,New Zealand Standard Time (Pacific/Auckland)
Pacific/Fiji,+12:00,+13:00,True,GMT+12:00,Fiji Time (Pacific/Fiji)
Asia/Kamchatka,+12:00,+12:00,False,GMT+12:00,Petropavlovsk-Kamchatski Time (Asia/Kamchatka)
Pacific/Norfolk,+11:00,+11:00,False,GMT+11:30,Norfolk Time (Pacific/Norfolk)
Australia/Lord_Howe,+10:30,+11:00,True,GMT+11:00,Lord Howe Standard Time (Australia/Lord_Howe)
Pacific/Guadalcanal,+11:00,+11:00,False,GMT+11:00,Solomon Is. Time (Pacific/Guadalcanal)
 Australia/Adelaide,+09:30,+10:30,True,GMT+10:30,Australian Central Standard Time ((South Australia) Australia/Adelaide)
Australia/Sydney,+10:00,+11:00,True,GMT+10:00,Australian Eastern StandardTime (New South Wales) (Australia/Sydney)
Australia/Brisbane,+10:00,+10:00,False,GMT+10:00,Australian Eastern Standard Time (Queensland) (Australia/Brisbane)
Australia/Darwin,+09:30,+09:30,False,GMT+09:30,Australian Central Standard Time (Northern Territory) (Australia/Darwin)
Asia/Seoul,+09:00,+09:00,False,GMT+09:00,Korea Standard Time (Asia/Seoul)
Asia/Tokyo,+09:00,+09:00,False,GMT+09:00,Japan Standard Time (Asia/Tokyo)
Asia/Hong_Kong,+08:00,+08:00,False,GMT+08:00,Hong Kong Time (Asia/Hong_Kong)
Asia/Kuala_Lumpur,+08:00,+08:00,False,GMT+08:00,Malaysia Time (Asia/Kuala_Lumpur)
Asia/Manila,+08:00,+08:00,False,GMT+08:00,Philippines Time (Asia/Manila)
Asia/Shanghai,+08:00,+08:00,False,GMT+08:00,China Standard Time (Asia/Shanghai)
Asia/Singapore,+08:00,+08:00,False,GMT+08:00,Singapore Time (Asia/Singapore)
Asia/Taipei,+08:00,+08:00,False,GMT+08:00,China Standard Time (Asia/Taipei)
Australia/Perth,+08:00,+08:00,False,GMT+08:00,Australian Western Standard Time (Australia/Perth)
Asia/Bangkok,+07:00,+07:00,False,GMT+07:00,Indochina Time (Asia/Bangkok)
Asia/Ho_Chi_Minh,+07:00,+07:00,False,GMT+07:00,Indochina Time (Asia/Ho_Chi_Minh)
Asia/Jakarta,+07:00,+07:00,False,GMT+07:00,West Indonesia Time (Asia/Jakarta)
Asia/Rangoon,+06:30,+06:30,False,GMT+06:30,Myanmar Time (Asia/Rangoon)
Asia/Dhaka,+06:00,+06:00,False,GMT+06:00,Bangladesh Time (Asia/Dhaka)
Asia/Kathmandu,+05:45,+05:45,False,GMT+05:45,Nepal Time (Asia/Kathmandu)
Asia/Colombo,+05:30,+05:30,False,GMT+05:30,India Standard Time (Asia/Colombo)
Asia/Kolkata,+05:30,+05:30,False,GMT+05:30,India Standard Time (Asia/Kolkata)
Asia/Karachi,+05:00,+05:00,False,GMT+05:00,Pakistan Time (Asia/Karachi)
Asia/Tashkent,+05:00,+05:00,False,GMT+05:00,Uzbekistan Time (Asia/Tashkent)
Asia/Yekaterinburg,+05:00,+05:00,False,GMT+05:00,Yekaterinburg Time (Asia/Yekaterinburg)
Asia/Kabul,+04:30,+04:30,False,GMT+04:30,Afghanistan Time (Asia/Kabul)
Asia/Baku,+04:00,+05:00,True,GMT+04:00,Azerbaijan Summer Time (Asia/Baku)
Asia/Dubai,+04:00,+04:00,False,GMT+04:00,Gulf Standard Time (Asia/Dubai)
Asia/Tbilisi,+04:00,+04:00,False,GMT+04:00,Georgia Time (Asia/Tbilisi)
Asia/Yerevan,+04:00,+04:00,False,GMT+04:00,Armenia Time (Asia/Yerevan)
Asia/Tehran,+03:30,+04:30,True,GMT+03:30,Iran Daylight Time (Asia/Tehran)
Africa/Nairobi,+03:00,+03:00,False,GMT+03:00,East African Time (Africa/Nairobi)
Asia/Baghdad,+03:00,+03:00,False,GMT+03:00,Arabia Standard Time (Asia/Baghdad)
Asia/Kuwait,+03:00,+03:00,False,GMT+03:00,Arabia Standard Time (Asia/Kuwait)
Asia/Riyadh,+03:00,+03:00,False,GMT+03:00,Arabia Standard Time (Asia/Riyadh)
Europe/Minsk,+03:00,+03:00,False,GMT+03:00,Moscow Standard Time (Europe/Minsk)
Europe/Moscow,+03:00,+03:00,False,GMT+03:00,Moscow Standard Time (Europe/Moscow)
Africa/Cairo,+02:00,+02:00,False,GMT+03:00,Eastern European Summer Time (Africa/Cairo)
Asia/Beirut,+02:00,+03:00,True,GMT+03:00,Eastern European Summer Time (Asia/Beirut)
Asia/Jerusalem,+02:00,+03:00,True,GMT+03:00,Israel Daylight Time (Asia/Jerusalem)
Europe/Athens,+02:00,+03:00,True,GMT+03:00,Eastern European Summer Time (Europe/Athens)
Europe/Bucharest,+02:00,+03:00,True,GMT+03:00,Eastern European Summer Time (Europe/Bucharest)
Europe/Helsinki,+02:00,+03:00,True,GMT+03:00,Eastern European Summer Time (Europe/Helsinki)
Europe/Istanbul,+02:00,+03:00,True,GMT+03:00,Eastern European Summer Time (Europe/Istanbul)
Africa/Johannesburg,+02:00,+02:00,False,GMT+02:00,South Africa Standard Time (Africa/Johannesburg)
Europe/Amsterdam,+01:00,+02:00,True,GMT+02:00,Central European Summer Time (Europe/Amsterdam)
Europe/Berlin,+01:00,+02:00,True,GMT+02:00,Central European Summer Time (Europe/Berlin)
Europe/Brussels,+01:00,+02:00,True,GMT+02:00,Central European Summer Time (Europe/Brussels)
Europe/Paris,+01:00,+02:00,True,GMT+02:00,Central European Summer Time (Europe/Paris)
Europe/Prague,+01:00,+02:00,True,GMT+02:00,Central European Summer Time (Europe/Prague)
Europe/Rome,+01:00,+02:00,True,GMT+02:00,Central European Summer Time (Europe/Rome)
Europe/Lisbon,+00:00,+01:00,True,GMT+01:00,Western European Summer Time (Europe/Lisbon)
Africa/Algiers,+01:00,+01:00,False,GMT+01:00,Central European Time (Africa/Algiers)
Europe/London,+00:00,+01:00,True,GMT+01:00,British Summer Time (Europe/London)
Atlantic/Cape_Verde,-01:00,-01:00,False,GMT–01:00,Cape Verde Time (Atlantic/Cape_Verde)
Africa/Casablanca,+00:00,+01:00,True,GMT+00:00,Western European Time (Africa/Casablanca)
Europe/Dublin,+00:00,+01:00,True,GMT+00:00,Irish Summer Time (Europe/Dublin)
GMT,+00:00,+00:00,False,GMT+00:00,Greenwich Mean Time (GMT)
America/Scoresbysund,-01:00,+00:00,True,GMT–00:00,Eastern Greenland Summer Time (America/Scoresbysund)
Atlantic/Azores,-01:00,+00:00,True,GMT–00:00,Azores Summer Time (Atlantic/Azores)
Atlantic/South_Georgia,-02:00,-02:00,False,GMT–02:00,South Georgia Standard Time (Atlantic/South_Georgia)
America/St_Johns,-3:30,-02:30,True,GMT–02:30,Newfoundland Daylight Time (America/St_Johns)
America/Sao_Paulo,-03:00,-02:00,True,GMT–03:00,Brasilia Summer Time (America/Sao_Paulo)
America/Argentina/Buenos_Aires,-03:00,-03:00,False,GMT–03:00,Argentina Time (America/Argentina/Buenos_Aires)
America/Santiago,-03:00,-03:00,False,GMT–03:00,Chile Summer Time (America/Santiago)
America/Halifax,-04:00,-03:00,True,GMT–03:00,Atlantic Daylight Time (America/Halifax)
America/Puerto_Rico,-04:00,-04:00,False,GMT–04:00,Atlantic Standard Time (America/Puerto_Rico)
Atlantic/Bermuda,-04:00,-03:00,True,GMT–04:00,Atlantic Daylight Time (Atlantic/Bermuda)
America/Caracas,-04:30,-04:30,False,GMT–04:30,Venezuela Time (America/Caracas)
America/Indiana/Indianapolis,-05:00,-04:00,True,GMT–04:00,Eastern Daylight Time (America/Indiana/Indianapolis)
America/New_York,-05:00,-04:00,True,GMT–04:00,Eastern Daylight Time (America/New_York)
America/Bogota,-05:00,-05:00,False,GMT–05:00,Colombia Time (America/Bogota)
America/Lima,-05:00,-05:00,False,GMT–05:00,Peru Time (America/Lima)
America/Panama,-05:00,-05:00,False,GMT–05:00,Eastern Standard Time (America/Panama)
America/Mexico_City,-06:00,-05:00,True,GMT–05:00,Central Daylight Time (America/Mexico_City)
America/Chicago,-06:00,-05:00,True,GMT–05:00,Central Daylight Time (America/Chicago)
America/El_Salvador,-06:00,-06:00,False,GMT–06:00,Central Standard Time (America/El_Salvador)
America/Denver,-07:00,-06:00,True,GMT–06:00,Mountain Daylight Time (America/Denver)
America/Mazatlan,-07:00,-06:00,True,GMT–06:00,Mountain Standard Time (America/Mazatlan)
America/Phoenix,-07:00,-07:00,False,GMT–07:00,Mountain Standard Time (America/Phoenix)
America/Los_Angeles,-08:00,-07:00,True,GMT–07:00,Pacific Daylight Time (America/Los_Angeles)
America/Tijuana,-08:00,-07:00,True,GMT–07:00,Pacific Daylight Time (America/Tijuana)
Pacific/Pitcairn,-08:00,-08:00,False,GMT–08:00,Pitcairn Standard Time (Pacific/Pitcairn)
America/Anchorage,-09:00,-08:00,True,GMT–08:00,Alaska Daylight Time (America/Anchorage)
Pacific/Gambier,-09:00,-09:00,False,GMT–09:00,Gambier Time (Pacific/Gambier)
America/Adak,-10:00,-09:00,True,GMT–9:00,Hawaii-Aleutian Standard Time (America/Adak)
Pacific/Marquesas,-09:30,-09:30,False,GMT–09:30,Marquesas Time (Pacific/Marquesas)
Pacific/Honolulu,-10:00,-10:00,False,GMT–10:00,Hawaii-Aleutian Standard Time (Pacific/Honolulu)
Pacific/Niue,-11:00,-11:00,False,GMT–11:00,Niue Time (Pacific/Niue)
Pacific/Pago_Pago,-11:00,-11:00,False,GMT–11:00,Samoa Standard Time (Pacific/Pago_Pago)

 
Venkat PolisettiVenkat Polisetti
I know this is a very old thread but now you can use:

String tz = UserInfo.getTimeZone().getDisplayName();

which would give you Eastern Standard Time, if the logged in user's timezone is set to EST.