·您当前的位置:首页 > 技术教程 > AS2与AS3技术 >

[AS3]as3使用日期和时间的例子源代码

时间:2016-10-08 23:12酷播
[AS3]as3使用日期和时间的例子源代码,日历日期时间及时间间隔,计时分别由Date类,flash.utile.Timer类来提供

[AS3]as3使用日期和时间的例子源代码,日历日期时间及时间间隔,计时分别由Date类,flash.utile.Timer类来提供。

* 日期时间

  1. //定义日期时间 
  2. var now:Date = new Date(); //无参数定义日期时间,为当前时间 
  3. var startTime:Date = new Date(1000*60*60*24); //1个参数毫秒数,自1970-1-1以来经过的毫秒数 
  4. var endTime:Date = new Date(2013,5,19,16,20,59,234); //参数为年、月、日、小时、分钟、秒和毫秒 
  5.  
  6.  
  7. //获取日期时间相应属性 
  8. /* 
  9. • fullYear 属性 
  10. • month 属性,以数字格式表示,分别以 0  到 11  表示一月到十二月 
  11. • date  属性,表示月中某一天的日历数字,范围为 1  到 31 
  12. • day 属性,以数字格式表示一周中的某一天,其中 0  表示星期日 
  13. • hours 属性,范围为 0  到 23 
  14. • minutes 属性 
  15. • seconds 属性 
  16. • milliseconds 属性 
  17. */ 

日期值在内部以毫秒形式保存,日期时间的加减运算可以换算成毫秒再加减。

* 时间间隔

  1. package   
  2.  {  
  3.  import flash.display.Sprite;  
  4.  import flash.events.TimerEvent;  
  5.  import flash.utils.Timer;  
  6.   
  7.   public class ShortTimer extends Sprite  
  8.   {  
  9.       public function ShortTimer()   
  10.       {  
  11.           // 酷播提示:creates a new five-second Timer  
  12.           var minuteTimer:Timer = new Timer(1000, 5);  
  13.          
  14.           // designates listeners for the interval and completion events  
  15.           minuteTimer.addEventListener(TimerEvent.TIMER, onTick); 
  16.           minuteTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete); 
  17.          
  18.           // starts the timer ticking  
  19.           minuteTimer.start(); 
  20.        }  
  21.   
  22.   public function onTick(event:TimerEvent):void   
  23.     {  
  24.       // displays the tick count so far  
  25.       // The target of this event is the Timer instance itself.  
  26.       trace("tick " + event.target.currentCount);  
  27.     }  
  28.   
  29.   public function onTimerComplete(event:TimerEvent):void  
  30.   {  
  31.          trace("酷播提示:Time's Up!");  
  32.   }  
  33.  } 

[AS3]as3使用日期和时间的例子源代码

热门文章推荐

请稍候...

保利威视云平台-轻松实现点播直播视频应用

酷播云数据统计分析跨平台播放器