Here, I posted only the code because practical is much useful than the theory so the need for an explanation just uses the below code...
<html>
<head runat="server">
<title>jQuery display current time on webpage</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
</script>
<script type="text/javascript">
// datetime make using jquery
$(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>
<script>
// date time make only javascript
function startTime()
{
var today = new Date();
var h = today.getHours();
var m = today.getMinutes();
var s = today.getSeconds();
var d = new Date();
var n = d.getDate();
var month = new Array();
month[0] = "January";
month[1] = "February";
month[2] = "March";
month[3] = "April";
month[4] = "May";
month[5] = "June";
month[6] = "July";
month[7] = "August";
month[8] = "September";
month[9] = "October";
month[10] = "November";
month[11] = "December";
var t = month[d.getMonth()];
var y = d.getFullYear();
m = checkTime(m);
s = checkTime(s);
document.getElementById('txt')
.innerHTML = n + "-" + t + "-" + y + " " + h + ":" + m + ":" + s;
var t = setTimeout(function ()
{
startTime()
}, 500);
}
function checkTime(i)
{
if(i < 10)
{
i = "0" + i
}; // add zero in front of numbers < 10
return i;
}
</script>
</head>
<body onload="startTime()">
<form id="form1">
<div> jQuery Display time second by second.
<label id="lblTime" style=" font-weight:bold"></label>
<br>
<br> Javascript Display time second by second. </div>
<div>
<div id="txt" style="color:#51545C; float:left; font-size:16px; font-weight:bold; margin-right: 12px;"></div>
</div>
</form>
</body>
</html>
Copy and Paste the above code and run the program and you will get the Current System updating date and time...
0 Comments