Home Javascript Javascriptexamples JavaScript Show Date



JavaScript Show Date
Posted on: April 18, 2011 at 12:00 AM
This page discusses - JavaScript Show Date

JavaScript Show Date

        

In this section, we are going to display the current date using JavaScript.

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:

<html>
<h2>Show Date</h2>
<script type="text/javascript">
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);
</script>
</html>

Output will be displayed as:

Download Source Code:

 

        

Related Tags for JavaScript Show Date:


More Tutorials from this section

Ask Questions?    Discuss: JavaScript Show Date  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.