DateTime gets converted in Salesforce from Postman

apexdatetimelightning-datatablepostman

I'm receiving a datetime string as a response in postman from a service. but when I'm converting the string value to date time. The value is getting converted to date time as expected but it is displaying the user time zone queried or used in table. Is it not possible to convert the date time value from string to dateTime and store in date Time field with the same value?

Best Answer

Date.valueOf is the wrong method, as it is meant to parse times in the user's time zone. You can use Date.valueOfGmt instead. Alternatively, consider JSON.deserialize:

DateTime transDateTime = (DateTime)JSON.deserialize(transDateString, DateTime.class);

This will allow you to parse the date time in GMT without any string manipulation.

Related Topic