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
tulasi ram 1tulasi ram 1 

get datetime based on time zone

how can we know or display datetime based on timezone. I have a time zone id of timezone-x, then how can i display datetime using that timezone Id. Pls help me on this.
Raj VakatiRaj Vakati
we need to use off set 

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_timezone.htm

 
TimeZone tz = UserInfo.getTimeZone();
System.debug('Display name: ' + tz.getDisplayName());
System.debug('ID: ' + tz.getID());
// During daylight saving time for the America/Los_Angeles time zone
System.debug('Offset: ' + tz.getOffset(DateTime.newInstance(2012,10,23,12,0,0)));
// Not during daylight saving time for the America/Los_Angeles time zone
System.debug('Offset: ' + tz.getOffset(DateTime.newInstance(2012,11,23,12,0,0)));
System.debug('String format: ' + tz.toString());

 
tulasi ram 1tulasi ram 1
Hi @raj vakati, thanks for reply. I need small clarification on below.
tz.getOffset(DateTime.newInstance(2012,10,23,12,0,0)) in this line 2012,10,23,12,0,0 what is this time. Why they are using this particular time, Can i set it for current time.
Raj VakatiRaj Vakati
Yes .. you can try to use ant time  
 
TimeZone tz = UserInfo.getTimeZone();
System.debug('Display name: ' + tz.getDisplayName());
System.debug('ID: ' + tz.getID());
// During daylight saving time for the America/Los_Angeles time zone
System.debug('Offset: ' + tz.getOffset(DateTime.newInstance(2012,10,23,12,0,0)));
// Not during daylight saving time for the America/Los_Angeles time zone
System.debug('Offset: ' + tz.getOffset(DateTime.newInstance(2012,11,23,12,0,0)));
System.debug('String format: ' + tz.toString());