SOQL
queries in a client application return dateTime field values as Coordinated
Universal Time (UTC) values. You need to manually handle to convert this UTC
time zone to your User Time zone.
For
this salesforce provides, convertTimezone method. But You can use
convertTimezone() in a date function.
Refer more on convertTimeZone at https://www.salesforce.com/us/developer/docs/dbcom_soql_sosl/Content/sforce_api_calls_soql_select_convert_time_zone.htm
Let
see how to convert UTC time zone to User Time Zone,
- DateTime scheduleTime = DateTime.valueofGmt( ‘Your Date Time to be Convert’);
- // Get User time zone.
- Timezone userTimezone = UserInfo.getTimezone();
- Integer userOffset = userTimezone.getOffset(scheduleTime);
- // Get Organization time zone.
- Timezone orgTimeZone = Timezone.getTimezone('America/Los_Angeles');
- Integer orgOffset = orgTimezone.getoffset(scheduleTime);
- Integer offsetDifference = orgOffset - userOffset;
- // DateTime is converted from UTC timezone to User Timezone
- DateTime correctedDateTime = scheduleTime.addMinutes(offsetDifference / (1000 * 60));
No comments:
Post a Comment