Date objectWe can display current date and time using JavaScript alert window by linking it to a button click event. We can place this button any where inside a page and display time and date once it is clicked by user. This is a simple script and we will try to develop better applications by learning such small examples.We will be using built in Date object. We can create instances of this object and use in our script like this
to display current date and time in alert windowNow this instance we can display by using JavaScript alert window.
To display the value we can use simple output command like this
The output will be like this Sat Jan 28 2012 10:17:04 GMT+0530 (India Standard Time)
Creating Date objectThis is the format to be used
Example :
Using button ClickNow this alert we will trigger when a button is clicked by a user. Here is onclick event of a button click.
Here is the demo, click this buttonHere is the complete code for the page with Show Time button.
Showing DD/MM/YYYY formatToday's Date
Displaying date and time.Full code to show updating date and time is here. Draw Analog Clock on HTML Canvas using Jquery or JavaScript. Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
![]() | ||||||||
▼ More on JavaScript Date
| ||||||||