I am getting date into JSON as below :
date=1382166999
It seems that date has been returned in milliseconds format.
Can anyone please suggest the way to convert it into normal date format and vice versa ?
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.
Sign up to join this communityThis is known as a "Unix Timestamp" (number of milliseconds since January 1st, 1970, 00:00:00 GMT). In Apex Code, you can use DateTime.newInstance(unixTimestamp)
to return a DateTime
that contains the formatted date/time value. In JavaScript, use new Date(unitTimestamp)
to get the same result. To convert back, in Apex Code, use myDate.getTime()
, and in JavaScript, use the same function: myDate.getTime()
.
DateTime dt = DateTime.newInstance(1667277663000); system.debug(dt);
but it is giving an error...Illegal integer
Nov 1, 2022 at 5:16
l
): DateTime dt = DateTime.newInstance(1667277663000l); system.debug(dt);