Animation

  1. Home
  2. Computing & Technology
  3. Animation

Flash Digital Clock

By Adrien-Luc Sanders, About.com

10 of 10

This is actually quite similar to the twenty-four hour clock code, even if it looks ten times longer. Instead of just retrieving hours, minutes, and seconds before concatenating them into a string and sending it to the dynamic text box, instead the script retrieves the three values, assigns each to its own variable, and then checks for certain conditions.

First it checks to see if the value of the hour returned is less than 12 (so basically from midnight until 11 AM) and, if so, it writes to a second dynamic text box telling it to display “AM”. If that condition isn’t met, then the else statement writes “PM” to the second text box.

Then the while statement says that while the value of the hour is greater than twelve, then twelve should be subtracted from the number assigned to the hour’s variable. So if getHours ( ) returns 13, then findhours will be set to 1 (1 p.m.).

Then it checks to see if the values of the hour, minutes, and seconds is less than 10, and if so, appends a text 0 in front of the value.

Lastly, it strings them all together and writes them to the dynamic text box.

Click here to view the example.

Explore Animation

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

Animation

  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.