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
cmarkcmark 

DateTime - convert to EDT

Hello.  In a Trigger, I want to take a datetime field and convert it to Eastern Daylight Time (always EDT - no matter what the time zone of the current user is).  I've tried using the format() method and passing the time zone that i want, but it always converts to GMT.  Is there a way to convert a Datetime object from one timezone to another?
Thanks
Chris
MikeGoelzerMikeGoelzer
You have to pass it the time zone's name in a very specific format:

string s = system.now().format('Z, zz, zzzz', 'America/Los_Angeles');
system.debug(s); // prints:  -0700, PDT, Pacific Daylight Time

s = system.now().format('Z, zz, zzzz', 'America/New_York');
system.debug(s); // prints:  -0400, EDT, Eastern Daylight Time

The list of all names is in the drop down for setting company business hours -- Setup -> Company or thereabouts.
SalesforceSSOSalesforceSSO

Here is what I am doing

GetserverTimeStamp
format it into "yyyy'-'MM'-'dd'T'HH':'mm':'ss'
writing to a file
then reading the timestamp from file in a string
then adding to a query with where LastModifiedDate >= timestamp


It is not giving the right records because ServerTimeStamp gives the GMT time.
how would I do that.
I get binding.geUserInfo.GetTimeZone();

like


but how do we convert it to ("yyyy'-'MM'-'dd'T'HH':'mm':'ss'- xx:xx) format