flex显示数字时钟和日期


  private function init():void{
  var timer:Timer = new Timer(1000);
  timer.addEventListener(TimerEvent.TIMER, this.resetTime);
  timer.start();
  }
  private function resetTime(event:TimerEvent):void{
  var today:Date = new Date();
  var dateFormatter:DateFormatter = new DateFormatter();   
  var timeFormatter:DateFormatter = new DateFormatter();
  dateFormatter.formatString = "YYYY年MM月DD日";  
  timeFormatter.formatString = "HH:NN:SS";
  var time:String = timeFormatter.format(today);
  var date:String = dateFormatter.format(today);  
  var week:Number = today.day;
  var weekStr:String = "星期";
  switch(week){
  case 0: weekStr += "日";
  break;
  case 1: weekStr += "一";
  break;
  case 2: weekStr += "二";
  break;
  case 3: weekStr += "三";
  break;
  case 4: weekStr += "四";
  break;
  case 5: weekStr += "五";
  break;
  case 6: weekStr += "六";
  break;
  }
  this.lb_date.text = date + " " + weekStr;    
  this.lb_time.text = time;  
  }
  width="150" height="21" right="111" top="9" id="lb_date"/>
  width="80" height="21" right="28" top="9" id="lb_time"/>

你可能感兴趣的:(Flex)