function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ugesh.galiUgesh.gali 

How to get user timezone in apex class

Is there any method to get user timezone in apex class.

Best Answer chosen by Admin (Salesforce Developers) 
Shashikant SharmaShashikant Sharma

User currentUser = [Select TimeZoneSidKey from User where id =: USerInfo.getUserId()];

All Answers

kiranmutturukiranmutturu

no there is no default method...but u can get the time zone by querying the field "TimeZoneSidKey"

Shashikant SharmaShashikant Sharma

User currentUser = [Select TimeZoneSidKey from User where id =: USerInfo.getUserId()];

This was selected as the best answer
magdielhfmagdielhf

No SOQL required, just

 

system.debug(' User Time Zone ID = '+UserInfo.getTimeZone().getID());

 

 

Joseph MinikJoseph Minik
UserInfo.getTimeZone() is the best way to do this. Querying for this information will work but will count against SF Governor Limits - avoid unnecessary queries whereever possible.