You need to sign in to do that
Don't have an account?

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.
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/
Schema.DescribeFieldResult fieldResult = User.TimeZoneSidKey.getdescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
for(Schema.PicklistEntry p : ple)
{
system.debug('###'+p.getlabel()+'****'+p.getValue()+'\n');
}
(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)
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.
String tz = UserInfo.getTimeZone().getDisplayName();
which would give you Eastern Standard Time, if the logged in user's timezone is set to EST.