# Digital clock

**URL:** <https://forum.kirupa.com/t/digital-clock/57120>\
**Category:** Uncategorized\
**Created:** [July 10, 2004, 2:56pm UTC](https://forum.kirupa.com/t/digital-clock/57120 "2004-07-10T14:56:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jedinitex](https://avatars.discourse-cdn.com/v4/letter/j/34f0e0/32.png) [@jedinitex](https://forum.kirupa.com/u/jedinitex)\
**Post date:** [July 10, 2004, 2:56pm UTC](https://forum.kirupa.com/t/digital-clock/57120/1 "2004-07-10T14:56:15Z")

</div>

I’m making a digital clock to put on my site. I used the tutorial from here on kirupa but i’m still having some trouble. For the minutes and hours, if the value is less than 10 it should have a zero in front of it, but it’s not showing up for me. I used the code that he had posted:

onClipEvent (enterFrame) {  
myTime = new Date();  
nSeconds = myTime.getSeconds();  
nMinutes = myTime.getMinutes();  
nHours = myTime.getHours();  
if (nHours\>=12) {  
ampm = “pm”;  
} else {  
ampm = “am”;  
}  
if (nHours\>=13) {  
nHours = nHours-12;  
}  
if (nHours==0) {  
nHours = 12;  
}  
if (length(nMinutes) == 1) {  
nHinutes = “0”+nMinutes;  
}  
if (length(nSeconds) == 1) {  
nSeconds = “0”+nSeconds;  
}  
nTime = nHours+":"+nMinutes+":"+nSeconds+" "+ampm;  
}

what’s wrong? Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 11, 2004, 8:48pm UTC](https://forum.kirupa.com/t/digital-clock/57120/2 "2004-07-11T20:48:00Z")

</div>

I still can’t figure it out, it seems like the code should work, but i’m still not getting the zeros in front of the minutes or seconds. Anyone got any ideas?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 12, 2004, 1:08am UTC](https://forum.kirupa.com/t/digital-clock/57120/3 "2004-07-12T01:08:14Z")

</div>

It should work, although _length()_ is a deprecated function.  
Also, there’s a typo on your code:

```auto
 if (length(nMinutes) == 1) {
n **M** inutes = "0"+nMinutes;
}

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 12, 2004, 3:59am UTC](https://forum.kirupa.com/t/digital-clock/57120/4 "2004-07-12T03:59:55Z")

</div>

Thanks man, i got the tutorial from here but didn’t even think to check for typos. it works now :pleased:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 12, 2004, 4:44am UTC](https://forum.kirupa.com/t/digital-clock/57120/5 "2004-07-12T04:44:28Z")

</div>

Anytime 😉
