I am getting the datetime value from the 3rd party. But when i try to store in the salesforce datetime field it gets stored in different TimeStamp.
For example :- 2022-08-09 14:40:00 -0400
I am getting the above value in the string format. But the correct time is 2022-08-09 10:40:00. How should i store in the salesforce datetime field with the correct timeStamp.
String billingDate = '2022-08-09 14:40:00 -0400';
DateTime dateTimeConvert = DateTime.valueOf(billingDate);
Integer valueOfHour = dateTimeConvert.hour();
Integer hourChange = Integer.valueOf(billingDate.substring(20, 23));
Integer changeInHour = valueOfHour + hourChange;
Opp.customDateTimeField__c = DateTime.newInstance(dateTimeConvert.year(),dateTimeConvert.month(),dateTimeConvert.day(),changeInHour,dateTimeConvert.minute(),dateTimeConvert.second());
Any help would be appreciated.