Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Initialize JavaScript Date to Midnight



To initialize a JavaScript Date to midnight, set hours like the following −

setHours(0,0,0,0);

Example

You can try to run the following code to set a date to midnight −

Live Demo

<!DOCTYPE html>
<html>
   <body>
      <script>
         var dt;
         dt = new Date();
         dt.setHours(0,0,0,0);
         document.write(dt);
      </script>
   </body>
</html>

Output

Mon May 28 2018 00:00:00 GMT+0530 (India Standard Time)
Updated on: 2020-06-18T09:15:34+05:30

459 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements