动态设置时间

package {
        import flash.display.Sprite;
        import flash.text.TextField;
        import flash.events.TimerEvent;
        import flash.utils.Timer;

        public class dynamicClock extends Sprite {
                private var dtate=new Date;
                private var txt:TextField=new TextField;
                private var tick:Timer;
                public function dynamicClock() {
                        init();
                        showTime();
                }
                private function init()
                {
                        txt.x=480;
                        txt.y=380;
                        txt.textColor=0xFF0010;
                        txt.selectable=false;
                        addChild(txt);
                }
                private function showTime():void {
                        tick=new Timer(1000);
                        tick.addEventListener(TimerEvent.TIMER,filltxt);
                        tick.start();
                }
                private function filltxt(event:TimerEvent):void {
                        dt=new Date;
                        txt.text=dt.toLocaleTimeString();
                }
        }
}

 

 


package common
{
 import flash.events.TimerEvent;
 import flash.utils.Timer;
 import mx.controls.TextInput;
 import mx.controls.Alert;
 
 
 /***
  * 获取当前时间
  ***/
 public class NonceTime
 {
  public function NonceTime()
  {
  }
  
  
  //定义一个定时器
  var tick:Timer;
  //定义时间对象
    var dt:Date = null;
    //定义一个文本框
    var ti:TextInput;
    //显示时间方法
    public function showTime(textInput:TextInput):void {
     //Alert.show("进入");
     ti = textInput;
     //1000毫秒调用一次
            tick=new Timer(1000);
            //添加监听方法
            tick.addEventListener(TimerEvent.TIMER,getTime);
            //启动定时器
            tick.start();
       }

    //获得当前时间
       function getTime(event:TimerEvent):void {
          dt = new Date();
          //获得当前的年、月、日、小时、分钟、秒,格式为“2010-4-3 22:25:29”
       ti.text = dt.fullYear.toString()+"-"+(dt.month+1).toString()+"-"+dt.date.toString()+" "+dt.hours.toString()+":"+dt.minutes.toString()+":"+dt.seconds.toString();
        }
  

 }
}


var svrCreateDate:Date = StringConvertDate.convertToDate(createTime);

 

你可能感兴趣的:(动态设置时间)