21 June 2013

Display Current Time on Webpage using Asp.net and jQuery


To display current time on website or webpage using jQuery we need to write the following code


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>jQuery display current time on webpage:Dotnet Total</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
</script>
<script type="text/javascript">
$(document).ready(function() {
ShowTime();
});
function ShowTime() {
var dt = new Date();
document.getElementById("lblTime").innerHTML = dt.toLocaleTimeString();
window.setTimeout("ShowTime()", 1000); // Here 1000(milliseconds) means one 1 Sec  
}
</script>
</head>
<body >
<form id="form1" runat="server">
<div>
jQuery Display time second by second.
<label id="lblTime" style=" font-weight:bold"></label>
</div>
</form>
</body>
</html>
Output


jQuery Display time second by second. 

No comments:

Post a Comment