1

I have googled it but no proper solution I found it in any salesforce community.

Scenario is we are making a callout and getting the response as string value like "2018-06-12T19:00:00-07:00". Now tricky part here is to convert into EST date time and update the record into salesforce.

Can any one please help on this ASAP?

2 Answers 2

2

Below code should get you the date time in EST:

String datetimeStr = '2018-06-12T19:00:00-07:00';
System.debug('=======datetimeStr=' + datetimeStr);

Datetime datetimeGMT = (Datetime)Json.deserialize('"' + datetimeStr + '"', 
Datetime.class);
System.debug('=======datetimeGMT=' + datetimeGMT);

String datetimeESTStr = datetimeGMT.format('yyyy-MM-dd\'T\'HH:mm:ssZ', 'EST');
System.debug('=======datetimeESTStr=' + datetimeESTStr);

enter image description here

1
  • Awesome! You made my day ....thank you very much @Bhoopender Commented Dec 16, 2019 at 7:27
0

You can use Date.valueOf('2018-06-12T19:00:00-07:00');

or Datetime.valueOf('...'); but in this case you have to format it the correct way.

Alternatively you can deserialize the string and create a date with

Datetime.newInstance(year,month,day,hours,minutes,seconds);

1
  • We will get error as invalid date time format Commented Dec 13, 2019 at 10:10

You must log in to answer this question.

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