Translate

Thursday 19 September 2013

Current Timing By Using Javascript

Screenshot:
        
                                                     

index.php:


</head>
<body>
  <div class="datewidget">  
  <p ><span id=curTime></span></p>
  </div>
</body>

Style.css:


<style>
.datewidget 
{ font-size: 11px; 
    color: #999; 
    padding: 5px 10px;
    width:100px;
    border:1px solid #CCC;
}
</style>

script:


<script type="text/javascript">
function DisplayTime(){
if (!document.all && !document.getElementById)
return
timeElement=document.getElementById? document.getElementById("curTime"): document.all.tick2
var CurrentDate=new Date()
var hours=CurrentDate.getHours()
var minutes=CurrentDate.getMinutes()
var seconds=CurrentDate.getSeconds()
var DayNight="PM"
if (hours<12) DayNight="AM";
if (hours>12) hours=hours-12;
if (hours==0) hours=12;
if (minutes<=9) minutes="0"+minutes;
if (seconds<=9) seconds="0"+seconds;
var currentTime=hours+":"+minutes+":"+seconds+" "+DayNight;
timeElement.innerHTML="<font style='font-family:verdana, arial,tahoma;font-size:12px;color:#E25984; font-weight:bold;'>"+currentTime+"</b>"
setTimeout("DisplayTime()",1000)
}
window.onload=DisplayTime
</script>

No comments:

Post a Comment