- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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)
Advertisements