Client Clock by javascript
Place the code below the head tag
<script language="Javascript" type="text/javascript">
setInterval("settime()", 1000);
function settime () {
var curtime = new Date();
var curhour = curtime.getHours();
var curmin = curtime.getMinutes();
var cursec = curtime.getSeconds();
var time = "";
if(curhour == 0) curhour = 12;
time = (curhour > 12 ? curhour - 12 : curhour) + ":" +
(curmin < 10 ? "0" : "") + curmin + ":" +
(cursec < 10 ? "0" : "") + cursec + " " +
(curhour > 12 ? "PM" : "AM");
document.getElementById('clock').value =time;
//document.getElementById('sample').value=time;
document.getElementById('mydiv').innerHTML ="<h3>"+time+"</h3>";
}
</script>
place the code below the body tag
<input type="text" id="clock" style="border: 0px;color:Green; font-weight:bold;" value="" />
<p id="sample"></p>
<div id="mydiv"></div>
Place the code below the head tag
<script language="Javascript" type="text/javascript">
setInterval("settime()", 1000);
function settime () {
var curtime = new Date();
var curhour = curtime.getHours();
var curmin = curtime.getMinutes();
var cursec = curtime.getSeconds();
var time = "";
if(curhour == 0) curhour = 12;
time = (curhour > 12 ? curhour - 12 : curhour) + ":" +
(curmin < 10 ? "0" : "") + curmin + ":" +
(cursec < 10 ? "0" : "") + cursec + " " +
(curhour > 12 ? "PM" : "AM");
document.getElementById('clock').value =time;
//document.getElementById('sample').value=time;
document.getElementById('mydiv').innerHTML ="<h3>"+time+"</h3>";
}
</script>
place the code below the body tag
<input type="text" id="clock" style="border: 0px;color:Green; font-weight:bold;" value="" />
<p id="sample"></p>
<div id="mydiv"></div>
Simplest Clock on Website..
ReplyDeletejavascript Clock is most usefull for every projects...
Delete
ReplyDeletefunction setTime() {
var dt = new Date();
var strDay = dt.getDay();
var strDate = dt.getDate();
strDate.toString().length == 1 ? strDate = "0" + strDate : strDate = strDate;
var strMonth = dt.getMonth();
var strYear = dt.getFullYear();
var strSecond = dt.getSeconds();
strSecond.toString().length == 1 ? strSecond = "0" + strSecond : strSecond = strSecond;
var strMinuite = dt.getMinutes();
strMinuite.toString().length == 1 ? strMinuite = "0" + strMinuite : strMinuite = strMinuite;
var strHour = dt.getHours();
strHour.toString().length == 1 ? strHour = "0" + strHour : strHour = strHour;
var monthArray = new Array("Jan", "Feb", "March", "April", "May", "June", "July", "Aug", "Sep", "Oct", "Nov", "Dec");
var dayArray = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
// var strFinalDate = monthArray[strMonth] + " " + dayArray[strDay] + " " + strYear.toString() + strHour.toString()+ " " + strMinuite.toString() + " " + strSecond.toString();
var strFinalDate = dayArray[strDay] + ", " + monthArray[strMonth] + " " + strDate + "," + " " + strYear + " " + strHour + ":" + strMinuite + ":" + strSecond;
document.getElementById("timeSpan").innerHTML = strFinalDate;
//timeSpan is the document ElementID
}
setInterval("setTime()", 1000);