am and pm altering my clock

  mco 12:49 27 Jul 2005

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 2005

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 2005

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 2005

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 2005

click here may be of use.

  mco 13:24 27 Jul 2005

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){

if (hours==0)

if (minutes<=9)

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


  Eric10 18:40 27 Jul 2005

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 2005

will give it a try thanks

  Eric10 19:02 27 Jul 2005

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 2005

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 2005

thanks again! Will try!

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

Elsewhere on IDG sites

Galaxy Note 8 vs iPhone X

Awful clip art from 1994 is being tweeted every hour by a bot

How to update iOS on iPhone or iPad

Les meilleures applications pour enfants 2017