码迷,mamicode.com
首页 > 其他好文 > 详细

[ActionScript 3.0] 简单倒计时

时间:2015-07-27 16:13:57      阅读:95      评论:0      收藏: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 }

 

[ActionScript 3.0] 简单倒计时

标签:

原文地址:http://www.cnblogs.com/frost-yen/p/4680401.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!