Search code examples
actionscript-3dateformatdatetime

Change Date Format in AS3


I've got this basic code :

var currentDate:Date = new Date()
   var tommorow:Date = new Date()
   var day3:Date = new Date()
   var day4:Date = new Date()

currentDate.setDate(currentDate.getDate());
tommorow.setDate(tommorow.getDate()+1);
day3.setDate(day3.getDate()+2);
day4.setDate(day4.getDate()+3);

If I do :

trace(day4);

It returns : Tue Sep 1 18:16:12 GMT+1100 2015

How can I format this date in order to return this : "Tuesday 1 september 2015" ?


Solution

  • This code works. you can copy this:

    var today:Date=new Date();
    var months:Array=["Jan","Feb","Mar","Apr","May","Jun","jul","Aug","Sep","Oct",
    "Nov","Dec"];
    //you can change them to your desired texts !
    
    var days:Array=["Sat","Sun","Mon","Tue","Wed","Thu","Fri"];
    
    var display:String=days[today.day]+" "+today.date+" "+months[today.month]+" "+today.fullYear;
    trace(display);
    

    now if you want to display the date of three days later , modify the today date.

    I H☻ P E this helps.