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
System Time using JavaScript
Kaushik S
Sep 17
2015
Code
977
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
<!DOCTYPE html>
<html xmlns=
"http://www.w3.org/1999/xhtml"
>
<head runat=
"server"
>
<title></title>
<style type=
"text/css"
>
.timer {
border-width: 1px;
text-align: center;
font-family: Algerian;
background-color: aqua;
width: 130px;
border-style: solid;
}
</style>
</head>
<body>
<form id=
"form1"
runat=
"server"
>
<div id=
"timeclock"
class
=
"timer"
></div>
</form>
<script type=
"text/javascript"
>
function getTimeFunc() {
//debugger;
var timeclock = document.getElementById(
"timeclock"
);
timeclock.innerHTML =
""
;
var getcurrdate =
new
Date();
var hr = parseInt(Math.floor(getcurrdate.getHours()));
var mi = parseInt( Math.floor(getcurrdate.getMinutes()));
var sc = parseInt(Math.floor(getcurrdate.getSeconds()));
var meridian =
"AM"
if
(hr > 12);
{
hr = hr - 12;
meridian=
"PM"
}
if
(hr == 0) {
hr =
"0"
;
}
if
(hr < 10)
{
hr =
"0"
+ hr;
}
if
(mi < 10) {
mi =
"0"
+ mi;
}
if
(sc < 10) {
sc =
"0"
+ sc;
}
var totalTime = hr +
":"
+ mi +
":"
+ sc +
" "
+ meridian;
timeclock.innerHTML =totalTime;
setTimeout(getTimeFunc, 1000);
}
getTimeFunc();
</script>
</body>
</html>
System Time
JavaScript