# Help! digital clock - am and pm?

**URL:** <https://forum.kirupa.com/t/help-digital-clock-am-and-pm/183940>\
**Category:** Uncategorized\
**Created:** [March 31, 2006, 11:58am UTC](https://forum.kirupa.com/t/help-digital-clock-am-and-pm/183940 "2006-03-31T11:58:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Edenbridge](https://avatars.discourse-cdn.com/v4/letter/e/97f17d/32.png) [@Edenbridge](https://forum.kirupa.com/u/Edenbridge)\
**Post date:** [March 31, 2006, 11:58am UTC](https://forum.kirupa.com/t/help-digital-clock-am-and-pm/183940/1 "2006-03-31T11:58:09Z")

</div>

Im doing a world clock. I dont know how to make the ‘ampm’ thing. I tried to do it by making some variable - ampm and made my code tried to make it for example:

> 

[COLOR=Blue]if/COLOR {  
hours=hours-24;  
}  
to become

> [COLOR=Blue]if/COLOR {  
> hours=hours-12;  
> }  
> [COLOR=Blue]if /COLOR {  
> ampm=“AM”;  
> } [COLOR=Blue]else[/COLOR] {  
> ampm=“PM”;  
> }

but maybe Im not doing it right cause the code doesnt work it shows me AM all the time. For now my clock works normally with 24 hour system - I mean 5:00 pm is 17:00. But I would like to make it in the way so it to look like 05:00pm. Do you know some tutorials for AM and PM specially?  
For now its made in the following way:

> 

[COLOR=Blue]function[/COLOR] UpdateClock(){  
myDate = [COLOR=Blue]new Date/COLOR;  
hours = myDate.[COLOR=Blue]getUTCHours/COLOR;  
[COLOR=Blue]if/COLOR {  
hours=hours-24;  
}  
minutes = myDate.[COLOR=Blue]getMinutes/COLOR;  
seconds = myDate.[COLOR=Blue]getSeconds/COLOR;  
sofia = myDate.[COLOR=Blue]getUTCHours/COLOR+2;  
[COLOR=Blue]if/COLOR {  
sofia=sofia-24;  
}  
minutes = myDate.[COLOR=Blue]getMinutes/COLOR;  
seconds = myDate.[COLOR=Blue]getSeconds/COLOR;  
}  
…  
[COLOR=Blue]if[/COLOR] (hours\<10) {  
hours = “0”+hours;

}  
if (sofia\<10) {  
sofia = “0”+sofia;

}

---

<div class="post-metadata">

**Author:** ![Bruno1](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/bruno1/32/2101_2.png) [@Bruno1](https://forum.kirupa.com/u/Bruno1)\
**Post date:** [March 31, 2006, 1:11pm UTC](https://forum.kirupa.com/t/help-digital-clock-am-and-pm/183940/2 "2006-03-31T13:11:32Z")

</div>

```auto

if(hours>12) {
ampm="PM";
hours -= 12;
}else if (hour == 0) {
hour = 12;
} else {
ampm = "AM";
}

```

salut

---

<div class="post-metadata">

**Author:** ![nathan99](https://avatars.discourse-cdn.com/v4/letter/n/96bed5/32.png) [@nathan99](https://forum.kirupa.com/u/nathan99)\
**Post date:** [March 31, 2006, 9:54pm UTC](https://forum.kirupa.com/t/help-digital-clock-am-and-pm/183940/3 "2006-03-31T21:54:10Z")

</div>

Digital: [http://www.n99creations.com/?pID=archives&col=Blue&arch=Digital\_Clock](http://www.n99creations.com/?pID=archives&col=Blue&arch=Digital_Clock)  
Analogue: [http://www.n99creations.com/?pID=archives&col=Blue&arch=Analogue\_Clock](http://www.n99creations.com/?pID=archives&col=Blue&arch=Analogue_Clock)

EDIT:  
Second, I will make a world one.  
[http://www.n99creations.com/?pID=archives&col=Blue](http://www.n99creations.com/?pID=archives&col=Blue) , should be there
