Flash actionscript 3.0: how to get he System time in action script 3.0

how to get he System time in action script 3.0

Posted by Sankar.G | Posted in | Posted on 12:27 PM

you can get the system in action script 3.0 code is follows

code:
import flash.utils.*;
var ti:Timer=new Timer(1000);
ti.addEventListener(TimerEvent.TIMER,fun);
ti.start();
function fun(e:Event)
{
var a:Date=new Date();
if(a.hours>=13)
{
str = "PM"
}
else
{
str = "AM"
}
t1_txt.text=Number(a.getHours()).toString()+":"+Number(a.getMinutes()).toString()+":" +Number(a.getSeconds()).toString()+" "+str;
}

for this we want to import a library utils
and declare a variable t1 as a timer and 1000 is milliseconds timer will tick per second if you set 500 it will 2 times for a second and addeventlistener for that timer and start the timer
and we declare a variable a as date
and use gethour ,get minutes, get seconds is used to get the system times

Comments (3)

good post!

this is really helpful.
How would you show the leading zero? For example, right now it displays 11:23:9, instead of 11:23:09

How would you ad AM/PM?
Thanks

Hi,

I update the postm Now you can get AM or PM easily

http://script3.blogspot.in/2008/08/how-to-get-he-system-time-in-action.html