Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Display Live Date And Time Using JavaScript and JQuery
WhatsApp
Mohd Arif
Nov 24
2015
11.5
k
0
1
<html xmlns=
"http://www.w3.org/1999/xhtml"
>
<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>
Javascript
time
jquery time
live time
real time
Up Next
Display Live Date And Time Using JavaScript and JQuery