Non-Military Clocks

Hello Everyone,

This is my first post on the entire board, so I would like to start off by saying it is nice meeting you all. I am 18 and new at this flash actionscript stuff. I have done Javascript and DHTML, so hopefully this will help me learn Actionscript a little easier. First problem I had with Actionscript is that no one ever seems to have a tutorial for making a Non-Military Time digial clock. I didn’t look too hard, but I couldn’t find one, so I decided to be on my own and make one. Well, I made one that worked, which is good.

I wrote a tutorial on it in case anyone wants to read it. It is the first tutorial I have ever written in my life, it doesn’t have example pictures yet, but I am working on it. There is an example of what I am talking about at the end of page.

Click Here Non-Military Time Tutorial to check out the tutorial. Hopefully it will come in handy. Remember I am new at this, so if there are any useless chunks of code or bad explanations, I am sorry.

Enjoy,
Shane (lostinbeta)

Hey Shane,

Great job for writing your first tutorial! I added it to the bottom of my site (minus the milliseconds).

I played with the code a bit, to see if I could make a zero appear before the single digit hour (ex. 03:24:56 instead of 3 :24:56).

Any ideas? I can’t seem to get it to work. I tried using the code you used for the minutes and seconds, and adapt it to the hour part. Here is the original code:

function updateTime() {
myTime = new Date();
milliseconds = myTime.getMilliseconds();
seconds = myTime.getSeconds().toString();
while (seconds.length<2) {
seconds = “0”+seconds;
}
minutes = myTime.getMinutes().toString();
while (minutes.length<2) {
minutes = “0”+minutes;
}
hours = myTime.getHours().toString();
delete myTime;
for (clock; (hours>=13); hours-=12) {
}
for (clock; (hours==0); hours=12) {
}
}
fscommand(“allowscale”, false);
stop();

Here is what I’ve done to it to try and make the hours always be 2 digits:

function updateTime() {
myTime = new Date();
milliseconds = myTime.getMilliseconds();
seconds = myTime.getSeconds().toString();
while (seconds.length<2) {
seconds = “0”+seconds;
}
minutes = myTime.getMinutes().toString();
while (minutes.length<2) {
minutes = “0”+minutes;
}
hours = myTime.getHours().toString();
while (hours.length<2) {
hours = “0”+hours;
}
delete myTime;
for (clock; (hours>=13); hours-=12) {
}
for (clock; (hours==0); hours=12) {
}
}
fscommand(“allowscale”, false);
stop();

…any ideas?

Anyhow, great job on the tutorial bro. I enjoyed it.

Check it out at my site, if ya like.

Yeah, I have been having complications with adding the 0 there too. I have no clue why, but I am not that good with Actionscript yet. Hopefully I will find a fix for it later on.

Thanks for the compliment on the tutorial, and for using it on your site =)

Your site is pretty good. Keep up the good work. And congrats on winning the 2002-2003 Golden Web Award:)

Your site does run a little slow on my machine. May be my computer, but in case it isn’t, you might want to up your FPS rate.

Hi there. I have a clock tutorial on this site already, using different methods. Here is my tutorial, however some of the code is wrong…

http://www.kirupa.com/developer/actionscript/digital_clock.asp

The code that is given on the site is correct, however the code that is in the Final Source FLA is not right. Check it out because it shows how to put a ‘0’ in front of the numbers.

Oh hey, check that out a clock tutorial on Kirupa, I couldn’t find that, I musta skimmed over it or something. Does that clock have non-military time? That is what I always had trouble finding. That is why I created my tutorial.

Hmmm, is the flash movie playing on the page correct? It doesn’t show a 0 before the 1 (it is 1am)

Hmm, there is no zero, but it seems the digit has moved over to the left ( or appears so) and doesn’t leave the gap we were speaking of, Shane.

I’m still working on tweeking the code you wrote…

no, it doesn’t have a 0 in front of the 1 for the hour, but it has zeros in front of the minutes and the seconds…use the same principle. Its just an if statement.

if(length(nHours) == 1){
nHours = “0”+nHours
}

Yes, that would make sense. And it does work. Thank You. Why don’t I ever think of the little things. I always make things difficult for myself, lol

The new tutorial is up and posted. It has the added code and the added example that shows the 0 before the hour works.

You can View it here Non-Military Clock Tutorial

Great tutorial…we just took different routes to achieve a similar goal. :slight_smile:

Nice work guys… they are both great tutorials. :slight_smile:

This is what I tried doing to the code yesterday, but I must have misses a bracket or something, because I still couldn’t get it to work.

Thanks again!

ooh lostinbeta’s first post, sorry if this bump up was pointless :-\

:stuck_out_tongue:

Wow, I completely forgot what my first post was=)

Thanks for bumping this up and refreshing my memory :slight_smile:

looks at the stars
My first post, back on the old forum, was about post incrementation, I still remember. I was VERY intimidated, but I quickly became David’s and Thor’s padawan :stuck_out_tongue:

I am still very intimidated :stuck_out_tongue:

Getting there though. I am the new padawan I suppose :slight_smile:

two thousand and seven hundred posts later… :stuck_out_tongue:

Yep, exactly. I posted this post as my 2700th post on the dot :slight_smile:

So this post right here marks that occasion =)

my first post was a ? i gotta go dig mine up now.

No need… I found it for you… in site check.

Here it is…

how did you find it?! thanks! mine is nothing compared to yours but i love it still!:beam: