Activity Forums Salesforce® Discussions How to convert a timestamp value to datetime in apex?

  • Nitish

    Member
    May 25, 2016 at 10:17 am

    Hi Ajit,

    This 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().

  • Tanu

    Member
    October 16, 2017 at 2:56 pm

    I am getting wrong value of timestamp  "201708161100" by this way, so please help me to get right answer.
    You can validate your answer here Convert Timestamp to date.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos