PDA

View Full Version : JavaScript local local time script 24 hr format?



eddiy
02-15-2013, 12:58 AM
Hi,

Can someone please show me how to use a 24 hr format with the
JavaScript local time script?, it has 12 hr by default.

Thanks

Ey

Its located here
http://www.dynamicdrive.com/dynamicindex6/localtime.htm



mod's note:

Welcome to DynamicDrive, eddiy!

Please don't double-post.

Sometimes, new posts are caught in the forum's anti-spam software. We review all moderated posts as soon as quickly as possible, so please be patient. Posting again only slows the process by increasing the amount of work we need to do. :)

thanks!

vwphillips
02-15-2013, 11:07 AM
showLocalTime.prototype.updateContainer=function(){
var thisobj=this
if (this.displayversion=="long")
this.container.innerHTML=this.localtime.toLocaleString()
else{
var hour=this.localtime.getHours()
var minutes=this.localtime.getMinutes()
var seconds=this.localtime.getSeconds()
var ampm=''
var dayofweek=weekdaystxt[this.localtime.getDay()]
this.container.innerHTML=formatField(hour, 1)+":"+formatField(minutes)+":"+formatField(seconds)+" "+ampm+" ("+dayofweek+")"
}
setTimeout(function(){thisobj.updateContainer()}, 1000) //update container every second
}

function formatField(num, isHour){
if (typeof isHour!="undefined"){ //if this is the hour field
}
return (num<=9)? "0"+num : num//if this is minute or sec field
}