1

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?

2 Answers2

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
0

Try integer.valueOf instead of long.valueOf

Steve Judd
  • 218
  • 2
  • 6