am and pm altering my clock

  mco 12:49 27 Jul 05
Locked

I've copied and pasted a digital 12 hour clock onto my site -tells the time fine but between 12 and 1 lunchtime it's still saying am, not pm. Can anyone tell me how to alter the code to make it change to pm from 12 lunchtime? (I'm not at the creating my own html stage yet but can recognise the bits to alter font, colour and size and I can see where the hours/minutes/secs bits are so could anyone advise please?) Or better still how to make it 24 hours?

  Gaz 25 12:52 27 Jul 05

Control Panel > Date, Time, Language and Reg. settings. > Change the format of numbers, dates and times. > Customise > Click time tab > change HH:MM:SS:TT

To > h:mm:ss:tt

  mco 12:57 27 Jul 05

sorry - you've lost me...I was asking for how to alter the html code I've pasted up - aren't you talking about my pc? Is it my pc's clock that's wrong then?

  Gaz 25 13:03 27 Jul 05

Generally html/javascript clock codes do take the time from the PC, yes.

Check your clock is correct first. Then we will look at the script.

  Gaz 25 13:04 27 Jul 05

click here may be of use.

  mco 13:24 27 Jul 05

my pc clocks ok (24 hour clock actually) Here's the bit of script I'm trying to alter:

var Digital=new Date()
var hours=Digital.getHours()
var minutes=Digital.getMinutes()
var seconds=Digital.getSeconds()
var dn="AM"

if (hours>12){
dn="PM"
hours=hours-12
}

if (hours==0)
hours=12

if (minutes<=9)
minutes="0"+minutes

if (seconds<=9)
seconds="0"+seconds
var ctime=hours+":"+minutes+":"+seconds+" "+dn
tick2.innerHTML="<b style='font-size:14;color:003366;'>"+ctime+"</b>"
setTimeout("show2()",1000)
}

window.onload=show2
//-->
</script>

  Eric10 18:40 27 Jul 05

Try changing "if (hours>12){ dn="PM" hours=hours-12 }" to

"if (hours>=12){ dn="PM" hours=hours-12 }"

The original line says "if hours are greater than 12" while the changed line says "if hours are greater than or equal to 12". I'm not a javascript expert but I think that should do it.

  mco 18:51 27 Jul 05

will give it a try thanks

  Eric10 19:02 27 Jul 05

This code seems to be what decides when to show AM or PM

var dn="AM"

if (hours>12){ dn="PM" hours=hours-12 }

if (hours==0) hours=12

You could try leaving it out altogether then I think it may show in 24 hour format.

Please keep a copy of your original code before playing with it as I would hate to destroy it for you.

  Eric10 19:08 27 Jul 05

also for 24 hour format you'd need to leave out the "dn" before tick2.innerHTML on the line that starts with "if (seconds<=9)" as this just writes AM or PM to the time string.

  mco 22:43 27 Jul 05

thanks again! Will try!

This thread is now locked and can not be replied to.

What is ransomware and how do I protect my PC from WannaCry?

Disney layout supervisor Rob Dressel on the challenges of visualising Moana

Siri vs Google Assistant