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: 6.06 Votes: 34
(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: S.Saipriya
» Title: Flash Fire Effect
» Description: This tutorial explains about how to create Fire Effect in Flash of Actionscript 2.0.I hope this tutorial helps you!
Featured Sound Loops
Image for equalize

Audio Player

» Author: Aidan Crouzet-Pascal
» Title: Falling Star
» Description: This loop is a cool sounding, E minor loop.
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: Brandan Paulin
» Description: Epic sounding loop with Brass, Percussion, Strings and Winds. This is actually part of a Loop Pack called the Coming where you can download the rest of the loops that go with it FREE from my website.