812
In this example we will display the current date and time in JavaScript
Example 1
// get local machine date time const date = new Date(); // get the date as a string const datenow = date.toDateString(); // get the time as a string const time = date.toLocaleTimeString(); // display date console.log('Date: ' + datenow); // display time console.log('Time: ' + time);
When you run this you will see something like this
Date: Wed Apr 13 2022 Time: 7:14:48 PM