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.

Example

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

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