Advertisement
728x90
You can use new Date() to generate a new Date object containing the current date and time. For example, let's display the current date in mm/dd/yyyy
javascript
1var today = new Date();
2
3var dd = String(today.getDate()).padStart(2, "0");
4
5var mm = String(today.getMonth() + 1).padStart(2, "0"); //January is 0!
6
7var yyyy = today.getFullYear();
8
9today = mm + "/" + dd + "/" + yyyy;
10
11document.write(today);Advertisement
Responsive Ad
🎯 Practice NowRelated Challenge
JavaScript Coding Exercise 48
Test your knowledge with this interactive coding challenge.
Start CodingAdvertisement
728x90
132of476