Skip to main content
Participant
July 25, 2017
Answered

date to display

  • July 25, 2017
  • 1 reply
  • 341 views

I want to create a swf file which displays date in the format Tuesday, July 25, 2017 and updates it with current time

please suggest me a solution.

    This topic has been closed for replies.
    Correct answer ClayUUID

    AS3 supports a more direct method for doing this sort of thing.

    function updateDate(evt:TimerEvent):void {

        var d:Date = new Date();

        var df:DateTimeFormatter = new DateTimeFormatter(LocaleID.DEFAULT);

        df.setDateTimePattern("EEEE, MMMM d, yyyy");

        var fd:String = df.format(d);

        trace(fd);

    }

    DateTimeFormatter - Adobe ActionScript® 3 (AS3 ) API Reference

    As for automatic updating, while you could schedule a timer to fire every 24 hours, the probability of timer drift is high. The function itself is so trivial that there would be no harm in calling it once a minute (every 60,000 milliseconds). So something like...

    var myTimer:Timer = new Timer(60000);

    myTimer.addEventListener(TimerEvent.TIMER, updateDate);

    myTimer.start();

    1 reply

    kglad
    Community Expert
    Community Expert
    July 25, 2017

    var d:Date;

    var dowA:Array=['Sunday','Monday',etc];

    var moyA:Array=['January','February',etc];

    var t:Timer=new Timer(1000,0;

    t.addEventListener(TimerEvent.TIMER,f);

    t.start();

    function f(e:TimerEvent):void{

    d=new Date();

    tf.text = formatF(d);

    }

    function formatF(d:Date):String{

    return dowA[d.day]+', '+moyA[d.month]+', '+d.fullYear;

    }

    ClayUUIDCorrect answer
    Legend
    July 25, 2017

    AS3 supports a more direct method for doing this sort of thing.

    function updateDate(evt:TimerEvent):void {

        var d:Date = new Date();

        var df:DateTimeFormatter = new DateTimeFormatter(LocaleID.DEFAULT);

        df.setDateTimePattern("EEEE, MMMM d, yyyy");

        var fd:String = df.format(d);

        trace(fd);

    }

    DateTimeFormatter - Adobe ActionScript® 3 (AS3 ) API Reference

    As for automatic updating, while you could schedule a timer to fire every 24 hours, the probability of timer drift is high. The function itself is so trivial that there would be no harm in calling it once a minute (every 60,000 milliseconds). So something like...

    var myTimer:Timer = new Timer(60000);

    myTimer.addEventListener(TimerEvent.TIMER, updateDate);

    myTimer.start();