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:
Tutorials
- Clear cookie example
- JavaScript getElementById innerHTML
- JavaScript getElementById Style
- Javascript Examples
- JavaScript add row dynamically to table
- New Page 1
- JavaScript Change link
- JavaScript Checkbox getElementById
- javascript clear textarea
- JavaScript Clock Timer
- JavaScript Cookies
- JavaScript Date Difference
- JavaScript duplicate string
- JavaScript Email Validation
- javascript focus input
- JavaScript get excel file data
- JavaScript getAttribute Href
- JavaScript getAttribute Style
- JavaScript getElementById div
- JavaScript getElementById Iframe
- JavaScript getElementById select
- JavaScript Hide Button
- JavaScript Hide Div
- JavaScript hide image
- JavaScript Hide Table Column
- JavaScript Hide Table Rows
- JavaScript Key Event
- JavaScript link
- JavaScript method location
- JavaScript move div
- JavaScript move file
- JavaScript move image
- JavaScript Navigate Back
- JavaScript navigate to page
- JavaScript Navigate to URL
- JavaScript indexOf substring
- JavaScript onkeypress event
- JavaScript Open file
- JavaScript Open link in new window
- JavaScript Open Modal Window


