Display Time with JavaScript

In some cases, we have to show the system time dynamically.
In that case we need to consider current hours, minutes and seconds.

we can show browser time with the help of javascript dynamically.
For this I use the setTimeout function to display time dynamically.

The code to display time with javascript like below.

    
<html> <head> <script type="text/javascript"> function time_display(){ var time = new Date() var hours = time.getHours() var minutes = time.getMinutes() minutes=((minutes < 10) ? "0" : "") + minutes var seconds = time.getSeconds() seconds=((seconds < 10) ? "0" : "") + seconds var clock = hours + ":" + minutes + ":" + seconds document.getElementById('lbl_time').innerHTML = clock setTimeout("time_display()",1000) } </script> </head> <body onload="time_display();"> <form> Time: <label id="lbl_time"></label> </form> </body> </html>

When you open the file in Browser you can output like below.

Time:
I tested this with major browsers like firefox,IE ..., it works fine.
Download source code here

Recent Articles

CLR integartion in SQL Server
Create, Read and Write Files in .Net
Message Queue in .Net
Deploy Asp.Net Web Site
Queues in Vb.Net
If you have any queries or doubts post at Forum
Share on Facebook
Responses(post your response or comments below)
Name *

Email * (won't be published)

Response *