1 Reply Latest reply on Apr 9, 2008 1:33 PM by Garyl Woolworth

    Help with Today's Date Display

    kdennis4 Level 1
      I have the following code:

      thisDate = new Date();
      var isToday:String;
      isToday = thisDate.getDate().toString() + "/" + thisDate.getMonth().toString() + "/" + thisDate.getFullYear().toString();

      For some strange reason it is populating with 9/3/2008????

      I added the alert to make sure. Any suggestions would be appreciated.
        • 1. Re: Help with Today's Date Display
          Garyl Woolworth Level 1
          Well first off you have your string mixed up, month comes before date. So that should be
          var isToday:String = thisDate.getMonth().toString() + "/" + thisDate.getDate().toString() + "/" + thisDate.getFullYear().toString();

          Then the second thing to take note of is something straight out of the live docs with the month.
          month : Number
          The month (0 for January, 1 for February, and so on) portion of a Date object according to local time.

          They start at 0 not 1. So you have two options either always add one to the month for the correct month if showing the number like that or format the date using a DateFormatter before you alert it. Which could be done like so.

          var df:DateFormatter = new DateFormatter();
          df.formatString = "MM/DD/YYYY";
          Alert.show(df.format(new Date()), "Full Date");

          Hope this helps.