Skip to content

Initialize JavaScript date to midnight

To set JavaScript date to midnight, we can use the setHours() method. Set hours, minutes, seconds and milliseconds to zeroes.

var dt = new Date();
//Thu Oct 01 2020 00:00:00 GMT+0530 (India Standard Time)

To set the date to next midnight, you can set hours as 24 in the setHours() method.

var dt = new Date();
//Fri Oct 02 2020 00:00:00 GMT+0530 (India Standard Time)
See also  Alternating Characters - Hackerrank Challenge - Java Solution

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.