First time here? First time here? Newsletter Signup Newsletter
651326 Members and growing! | Flash Jobs
Search tutorials
Author: Samaritan

How to make 2 digit time display. Simple.

Just a couple weeks ago I had to make a clock and calendar for a screensaver. And there is a problem that Flash returns minutes, seconds and any other time-related numbers as they are, e.g. 12:5:7. So the task here was to make this number into 12:05:07.

I happened to read a tutorial which suggested cheking each number separately and then setting it to two-digit if neccesarry. It looked like this: if minute == 1 then set it to minute = 01, else if second == 1 then set it 01 etc, etc... So to save any of you, who may follow a tute to do this, some extra time and annoying script duplications, may I suggest the following:

minute = (mydate.getMinutes());
if (Length(minute) == 1) {
    minute = "0" add minute;
}
second = (mydate.getSeconds());
if (Length(second) == 1) {
    second = "0" add second;
} 

Any explanation needed? What we do here is get the time, stick it into a variable, check the length (amount of characters) in that variable and in case this length is == to 1, add a zero right before it... and a few lines get the job done!

Good luck!

» Level Basic

Added: 2001-03-13
Rating: 5.83 Votes: 36
(10 being the highest)
» Author
No details available.
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!

Comments

  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: doc_chin7
» Description:

The flash's horizontal road drive was done in CS4 and was upgraded to CS6. The car responds to right/ left key and flash will auto-generate the movement of roads from left-right or right-left based on random number. Have fun driving in this virtual environment and avoid other cars... :) If you are creative, a road driving game can be created from it.

Featured Sound Loops
Image for equalize

Audio Player

» Author: BoxCat
» Title: CPU Talk
» Description: From the cyberpunk RPG, "Nameless: the Hackers" Completely Free to use! Keywords: edm hip hop rap electronic mysterious mission hacking chase exciting spy ios ambient chilling love happy sad angry suspense
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: nathan
» Description:

A recorded sound of the Dimensional Fork Gate.