You can see in the given example, we have created Date object which holds the current date and time. Now, in order to display the date, we have used getDate(), getMonth() and getFullYear() methods with the date object. We have added 1 to the month variable to display the month correctly because getMonth() method returns 0 for the month of January and 11 for December. When you load the following code, you will get the current date.
Here is the code:
var date = new Date();
var day = date.getDate();
var month = date.getMonth() + 1;
var year = date.getFullYear();
document.write("<b>Today's Date is :</b> "+day + "/" + month + "/" + year);
Output will be displayed as:
We have 1000s of tutorials on our website. Search Tutorials tutorials on our website.
Posted on: April 18, 2011 If you enjoyed this post then why not add us on Google+? Add us to your Circles