[ActionScript 3.0] 简单倒计时
1 import flash.utils.Timer; 2 import flash.events.TimerEvent; 3 import flash.text.TextField; 4 5 var text:TextField = new TextField(); 6 var endTime:Date = new Date(2015,7-1,29,15,30,0); 7 var timer:Timer = new Timer(1000); 8 text.autoSize = "left"; 9 this.addChild(text); 10 timer.addEventListener(TimerEvent.TIMER,onTimer); 11 timer.start(); 12 function onTimer(e:TimerEvent):void 13 { 14 text.text = formateCountdown(endTime,new Date()); 15 } 16 function formateCountdown(endTime:Date,nowTime:Date):String 17 { 18 var total:Number = Math.floor((endTime.getTime() - nowTime.getTime()) / 1000); 19 if (total > 0) { 20 var day:Number = Math.floor(total / 86400); 21 total = total - day * 60 * 60 * 24; 22 var hours:Number = Math.floor(total / 3600); 23 total = total - hours * 60 * 60; 24 var minutes:Number = Math.floor(total / 60); 25 total = total - minutes * 60; 26 var seconds:Number = total; 27 return day.toString()+"天"+hours.toString()+"时"+minutes.toString()+"分"+seconds.toString()+"秒"; 28 } 29 return "倒计时日期已过..."; 30 }
------------------------------------------------------------------
Always put yourself in the other's shoes.If you feel that it hurts you,it probably hurts others,too.------------------------------------------------------------------