AS3简单数字时钟

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了AS3简单数字时钟相关的知识,希望对你有一定的参考价值。

This example expects there to be a dynamic textfield on the stage with the instance name of 'myTextFieldOnStage'. Remember to embed the fonts (Numerals and Colon).
  1. import flash.text.TextField;
  2.  
  3. var timeTextfield:TextField = myTextFieldOnStage;
  4. timeTextfield.text = getFormattedTime();
  5.  
  6. var clockTimer:Timer = new Timer(1000, 0);
  7. clockTimer.addEventListener(TimerEvent.TIMER, onClockTimer);
  8. clockTimer.start();
  9.  
  10. function onClockTimer(e:TimerEvent):void {
  11. timeTextfield.text = getFormattedTime();
  12. }
  13.  
  14. function getFormattedTime():String {
  15. var now:Date = new Date();
  16. var hrs:String = String(now.getHours());
  17. if (hrs.length < 2) {
  18. hrs = "0" + hrs;
  19. }
  20. var mins:String = String(now.getMinutes());
  21. if (mins.length < 2) {
  22. mins = "0" + mins;
  23. }
  24. return hrs + ":" + mins;
  25. }

以上是关于AS3简单数字时钟的主要内容,如果未能解决你的问题,请参考以下文章

JS — 实现简单的数字时钟

HandlerThread实现数字时钟

vb.net开发简单的时钟程序??高手救救我!

[Java项目01][数字时钟]

[12小时Javascript Clock显示24时间,错误的AM / PM

golang代码片段(摘抄)