-4

In javascript, I have a timestamp value as a string. How to get Date from the same.

I know we can get a date from timestamp like below:

console.log(new Date(1535704620000)); Fri Aug 31 2018 14:07:00 GMT+0530 (India Standard Time)

But in my case, I want to get the value from the Timestamp value in the string as below:

console.log(new Date('1535704620000'));
Invalid Date

Thank you in advance.

1 Answers1

0

All you have to do is to turn the string passed into the Date constructor into a number, which can be done with the unary plus operator:

  new Date(+'1535704620000')
Jonas Wilms
  • 132,000
  • 20
  • 149
  • 151