quinta-feira, 29 de junho de 2017

Datas/Hora – relógio atualizado

       import flash.events.TimerEvent;
       import flash.utils.Timer;

       import mx.controls.Label;
       import mx.events.FlexEvent;

       public class DateTime extends Label  {
               private var dtNow:Date = new Date();
               private var timer:Timer;

               public function DateTime()  {
                       super();
                       this.addEventListener(FlexEvent.CREATION_COMPLETE,startTimer);
               }
               private function startTimer(e:FlexEvent):void{
                       timer = new Timer(1000);
                       timer.addEventListener(“timer”, atualizarHoras);
                       timer.start();
               }

               private function atualizarHoras(event:TimerEvent):void{
                       var now:Date = new Date();
                       var sMes:Array = new Array(
                               “Janeiro”,
                               “Fevereiro”,
                               “Março”,
                               “Abril”,
                               “Maio”,
                               “Junho”,
                               “Julho”,
                               “Agosto”,
                               “Setembro”,
                               “Outubro”,
                               “Novembro”,
                               “Dezembro”);
                       var sDiaSemana:Array = new Array(
                               “Domingo”,
                               “Segunda-Feira”,
                               “Terça-Feira”,
                               “Quarta-Feira”,
                               “Quinta-Feira”,
                               “Sexta-Feira”,
                               “Sábado”);

                       this.text = String(sDiaSemana[now.dayUTC] + ‘, ‘+
                               (dtNow.dateUTC < 10 ? “0” + dtNow.dateUTC:dtNow.dateUTC) +’ de ‘+
                               sMes[now.getMonth()]+’ de ‘+
                               now.getFullYear() +’ – ‘+
                               (now.getHours()   < 10 ? “0” + now.getHours()   :now.getHours())+':’+
                               (now.getMinutes() < 10 ? “0” + now.getMinutes() : now.getMinutes())+':’+
                               (now.getSeconds() < 10 ? “0” + now.getSeconds() :now.getSeconds())
                       );
               }
       }


Faça seu comentário