How do I get the current date and time in JavaScript?

JavascriptWeb DevelopmentFront End Technology

To get the current date and time in JavaScript, use the getDate() method.


You can try to run the following code get the date and time:

<!DOCTYPE html>
      <p>Today's Date and Time</p>
      <button onclick="myFunction()">Get Date & Time</button>
      <p id="test"></p>
         function myFunction() {
            var date = new Date();
            document.getElementById("test").innerHTML = date;
Published on 09-Jan-2018 08:26:07