Written by: Johan Jansen
Difficulty Level: Beginner
Requirements: Flash 5
Download FLA

How to make the 2 digit display in the time ?? ( update for creating the time with flash 5 )

1 Breaking the code into 3 different displays

You have the following code from my previous tutorial
mydate = new Date();

Now break it into three times instead of one :
time = mydate.getHours();
 time2 = mydate.getMinutes();
 time3 = mydate.getSeconds();

[Editor's note: In ActionScript 2.0 and above, 'time' is a reserved keyword, so you will have to substitute 'time1' or similar]
You must also add two variable textfields time2 and time3,your fla file should look like this :


2 Conversion of 1 digit to 2
If your minutes display " 1 " and not " 01 " , then you just have the add the " 0 " manually, so for each digit ( from one tille nine ) you PASTE the following code into your flash movie ( fla )

[Edit by Jesse Stratford]
It has been pointed out by many readers of this tutorial that the below method for "zero-padding" the time2 variable can written better as follows:
if (time2 < 10) {
    time2 = "0" + time2;

[End Edit by Jesse Stratford]

if (time2 == 1) {
  time2 = "01";
} else if (time2 == 2) {
  time2 = "02";

Then continue the code with ifelse untill you got all the numbers from 1 to 9

Do the same with the seconds ( time 3 instead off time 2 ). If you would like you can do the hours too, but there is no need to do that.
The code should like like this :

3 An extra option if your time is ahead or behind ( Hours only )
Setting the time ahead or behind, this is a bit more difficult. Some people mailed me about this topic,bcause for some reason my clock are some hours ahead or behind.

For each hour you set the clock ahead or behind there is another code, so I explain how this works.

If your time is one hour behind you must set the clock one hour ahead.

Use the follwing code to set the time one hour ahead
time = mydate.getHours() + 1;

The + 1 is to add one hour to the current time.

There is only one problem if it is 23 hours at the clock the time will be set to 24 hours , but this number has to zero ( 0 ) so have have to set the time manually to zero

by using if statements. Like this code :
if (time == 23) {
  time = "0";

If you fully want to understand how this works , you can study my example, I made the time from 4 hours behind till 4 hours ahead.

While writing this tutorial, the time passed by and I discovered several errors in my Beta_setting_time_ahead.fla, so the time won't be set to the correct value. I wasn't able to fix these, I hope someone can and will tell me how !

Good Luck !

Something about the author
I am 17 years old , live in Holland, near Rotterdam. Last your I passed my HAVO exams, now I doing VWO.
I like to create games and other amzing things with flash, I prefer Flash 4 as tool, I can't get used to flash 5, besides most people have / use the flash 4 plugin.

Some sites which I created with flash 4 or 5 :

www.geocities.com/flashra_jrj ( latest one )
www.geocities.com/flashoms_jrj ( handy chaotic menu )
www.geocities.com/flashsite_X ( Completely build with flash 5 )
www.geocities.com/flashsite_jrj ( first complete flash site )

Click here if you want to download my example for two digits.
Click here if you want to download my example for setting the time ahead