+ Start a Discussion
Shiva Ramesh @ xcdhrShiva Ramesh @ xcdhr 

Event StartDateTime conversion

Hi all


How to convert Event StartDateTime into User's Local Timezone. By default the time portion is always transferred in the Coordinated Universal Time (UTC) time zone. I need to convert into user's timezone. 

Shiva Ramesh @ xcdhrShiva Ramesh @ xcdhr

Hi all


I got it. Through this i have converted Event's StartDateTime UTC into User's local time zone.


User us = [Select id,TimeZoneSidKey from User where id=:'005d0000000alSH'];
TimeZone tz = TimeZone.getTimeZone(us.TimeZoneSidKey);
Datetime myDate = datetime.newInstance(2013, 7, 1, 13, 00, 0);
system.debug('*1time zone myDate*'+tz.getOffset(myDate));
integer correction = tz.getOffset(myDate);
DateTime correctedDateTime = myDate.addMinutes(correction / (1000 * 60));
System.debug('*1correctedDateTime: ' +correctedDateTime);


Thanks for posting the solution as well. Good work.
Shiva Ramesh @ xcdhrShiva Ramesh @ xcdhr

Thank You