Say we have the following Javascript date object and would like to display it as date and time.
const date = new Date();
Here’s how to using methods available on the date object itself:
const dateTimeString = date.toLocaleDateString() + ' ' + date.toLocaleTimeString();
The above will output "5/10/2019 11:49:44 AM"
(time of writing of this article).
Full code:
const date = new Date();
const dateTimeString = date.toLocaleDateString() + ' ' + date.toLocaleTimeString();
Happy coding!