How to get current date and time in JavaScript?


To get current date and time in JavaScript, use the Date object.

Example

You can try to run the following code to display date and time −

<!DOCTYPE html>
<html>
   <body>
      <p id="currentDate"></p>
      <script>
         document.getElementById("currentDate").innerHTML = Date();
      </script>
   </body>
</html>

varma
varma

e

Updated on: 16-Jun-2020

350 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements