0

I am making a callout to external system and I am receiving datetime like

18-10-07T18:00:00

Now, if I do like

String startDate = '2018-10-07T18:00:00';
DateTime testDateTime = DateTime.valueOf(String.valueOf(startDate).replace('T',' '));

Output That I get is : 2018-10-07 12:30:00 its in GMT format.

When I execute this code it takes current user timezone into consideration.

My logged in user time zone is IST so 12.30 GMT is 6 PM IST.So if I update datetime field and see value on pagelayout considering user timezone to IST it will show me 6 PM IST.

However what I want to achieve is, the string that I get from API is of EST timezone.
If '2018-10-07T18:00:00' , 6 PM EST is 3.30 AM IST then when I will store value of this String into datetime field at Salesforce side it should show me correct value based on logged in user timezone converting from EST.

Any thoughts would be appreciated.

2
  • 3
    Why does the API return time in EST? Why is it not in ISO 8601 format? You are aware of Daylight Savings Time, right? Best case scenario, this is a disaster waiting to happen. If possible, tell your API provider that you need a standard date/time format, ISO 8601, in GMT, just like what Salesforce uses. Don't make this any harder on yourself than it has to be.
    – sfdcfox
    Commented Sep 18, 2018 at 7:53
  • Yeah this make more sense to have date-time in ISO 8601 in GMT. Thanks @sfdcfox Commented Sep 18, 2018 at 8:57

2 Answers 2

1

You need to convert the date received 18-10-07T18:00:00 from EST timezone to GMT timezone and save this value into Salesforce.

Automatically the date will be displayed based on user's timezone.

Ideally, if the external system sends the datetime in GMT timezone then you dont need to convert that, just directly saving could have solved your purpose.

0
0

We are getting date and time from API in UTC format, like following

"startDateUtc": "2018-12-03T12:30:00"

so, if I do like DateTime.valueOfGmt(String.valueOf(startDateUtc).replace('T',' '));

and save value in SF this will solve my problem, we have asked our API provider to provide date in UTC format so than when we will store datetime in GMT format it will display value based on logged in user timezone.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .