I have requirement to to store the timestamp returned from the response to Salesforce DateTime. But the timestamp returned is in Unix format. How do I convert it to DateTime in Salesforce using apex?
Asked
Active
Viewed 2,015 times
2 Answers
2
This is a super old question, but I found an answer.
I was grabbing some data from a REST API that had a unix timestamp as the modified date. I needed to convert the unix timestamp into a Datetime object using Apex in Salesforce.
Also, make sure that the utcTime variable is cast as an Integer as Datetime.addSeconds() wants an Integer.
utcTime = 1376986594;
createdDate = Datetime.newInstanceGmt(1970, 1, 1, 0, 0, 0);
createdDate.addSeconds(utcTime);
System.debug('DateTime: ' + createdDate);

Mayday
- 76
- 5
-
Next time post the relevant snippet from that link. Your Link is now broken – compski Nov 18 '21 at 06:39
0
Try integer.valueOf instead of long.valueOf

Steve Judd
- 218
- 2
- 6
-
Thank you for your suggestion.I have tried using integar.valueOf but it does not help!! – Noopur Kharche Aug 08 '16 at 10:31