TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Display Live Date And Time Using JavaScript and JQuery
Mohd Arif
Nov 24
2015
Code
11.2
k
0
1
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
<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