PDA

View Full Version : Help on editing the Local Time script, I want 0's displayed before the hour.



MartinD2K5
11-01-2007, 11:44 PM
1) Script Title:
Local Time Script

2) Script URL (on DD):
http://www.dynamicdrive.com/dynamicindex6/localtime.htm

3) Describe problem:
Okay, what I exactly want is the script to display zeros before the hour, unless it's two numbers, for example:
01:00:00 AM
03:00:00 PM
11:00:00 AM
Something like that, I know that its something to do with this:


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

but I have no idea what.

Thanks!

Edit:
I think I got it! I messed around with the script a bit and I came up with this:


function formatField(num, isHour){
if (typeof isHour!="undefined"){ //if this is the hour field
var hour=(num>12)? num-12 : num
if (hour.toString().length==1)
hour="0"+hour
return (hour==0)? 12 :hour
}
return (num<=9)? "0"+num : num//if this is minute or sec field
}

If it seems wrong, tell me though, but this is solved for now.