1

There's an easy way to convert a string from an input to a timestamp?

For example... I got this:

"5/4/2018 11:49:01"

how do I convert that to this format?

"1522928905"
Sergio Mendez
  • 1,311
  • 8
  • 33
  • 56
  • I don't think it's exactly a duplicate, but this is similar and may help you: https://stackoverflow.com/questions/43202250/how-to-convert-string-to-date-in-angular2-typescript/43202323 – Rich Apr 05 '18 at 17:57

1 Answers1

4

You can just use the getTime() function of the date object.
For example:

let date = new Date("5/4/2018 11:49:01");
console.log(date.getTime());

getTime() returns the time in milliseconds, if you want the time in seconds just divide the result with 1000.

darron614
  • 893
  • 7
  • 15