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"
1

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.