I am trying to convert salesforce standard field CreatedDate to logged-in user's timezone. I am using following code
Datetime dt = Datetime.newInstance(a.CreatedDate.dateGmt(),a.CreatedDate.timeGmt());
But this is not giving right result.
for e.g. I have created a record at 11/12/2012 12:50 PM (in GMT+5:30)
. Now when another user (in GMT-5:00) logs into the system and run the above code in developer console then he should see 11/12/2012 2:20 AM
but he sees 11/12/2012 5:50 AM
.
What I am doing wrong? Any Thoughts?
Best Answer
For the method you're using, the documentation says the returned date is in the GMT Timezone.
This should do it
You can get the User's Timezinesidkey via a query to use dynamically per user