Sometimes, we want to convert string to datetime with JavaScript.
In this article, we’ll look at how to convert string to datetime with JavaScript.
How to convert string to datetime with JavaScript?
To convert string to datetime with JavaScript, we use the Date
constructor.
For instance, we write
const s = "01-01-2022 00:03:44";
const d = new Date(s);
console.log(d);
to call the Date
constructor with string to return a Date
object converted from the string.
Conclusion
To convert string to datetime with JavaScript, we use the Date
constructor.