1. Home
  2. Computing & Technology
  3. Animation

Flash Digital Clock

By , About.com Guide

9 of 10

This code both adjusts from twenty-four hour time to twelve hour time, and corrects a problem where hours, minutes, and seconds less than 10 only display a single digit:

onClipEvent (enterFrame) {
myclock=new Date() ;
var findhours = ((myclock.getHours())) ;
var findminutes=((myclock.getMinutes())) ;
var findseconds=((myclock.getSeconds())) ;
if (findhours<12) { _
root.ampm.text="AM";
}
else {
_root.ampm.text="PM";
}
while (findhours>12) {
findhours=findhours-12;
}
if (findhours<10) {
findhours="0" + findhours;
}
if (findminutes<10) {
findminutes="0" + findminutes;
}
if (findseconds<10) {
findseconds="0" + findseconds;
}
_root.timeclock.text=findhours + ":" + findminutes + ":" + findseconds;
}

Confused? Click to the next step to view an explanation of what this code does.

Explore Animation
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Animation
  4. Flash Animation Tutorials
  5. Flash Digital Clock

©2009 About.com, a part of The New York Times Company.

All rights reserved.