
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
What is the best way to initialize a 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 −
<!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)
- Related Articles
- What is the best way to initialize a JavaScript number?
- What is the best way to learn Vanilla JavaScript?
- What is the best way to concatenate strings in JavaScript?
- What is the best way to convert a number to a string in JavaScript?
- What is the best way to compare two strings in JavaScript?
- What is the best way to add an event in JavaScript?
- What is the best way to handle a Javascript popup using Selenium Webdriver?
- What is the best way to do optional function parameters in JavaScript?
- What is the best way to break from nested loops in JavaScript?
- Best way to store date/time in MongoDB?
- Can I extend a JavaScript error? What is the best way to do so?
- What is the best way to reduce and merge a collection of objects – JavaScript?
- Best way to change the date format in MySQL SELECT?
- What is the best way to log a Python exception?
- What is the best way to stop Brain Drain?

Advertisements