A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Can I format the Date in the DateField Component

  1. #1
    Member
    Join Date
    Jan 2004
    Posts
    43

    Can I format the Date in the DateField Component

    I searched for posts on this component, but didn't really find anything on formatting it. I'm using FlashMX2004pro, and when I just drag the component onto the stage, it's default format is in "18 Jul 2005".

    All I want to do is reformt this date so that it stores and displays MM/DD/YYYY format.

    Can this be done? Any help is greatly appreciated, thanks!

  2. #2
    Senior Member vevmesteren's Avatar
    Join Date
    Sep 2001
    Location
    Montréal, Québec
    Posts
    566
    http://flashmx2004.com/forums/index.php?showtopic=4805

    I use this dateformat.as function by Darron Shall. Unfortunatly it isn't available on the site currently, surely just a minor glitch.
    it is your mind that decides - it is with your mind that you fly


    vevmedia

  3. #3
    Hmm...
    Join Date
    Dec 2004
    Posts
    115
    Yes, this can be done. Flash explains how to do this in the help files. I did a search for datefield. Then look under using components.

    TJdub

  4. #4
    Member
    Join Date
    Jan 2004
    Posts
    43
    I found a function in the Help files, called Datefield.dateformatter, and it has a sample of what I want the date to look like:

    on (change) {
    dtfReceivedDate.dateFormatter = function(date){
    return d.getFullYear()+"/ "+(d.getMonth()+1)+"/ "+d.getDate();
    };

    }

    So I put this in the on change event of the component, but it doesn't work. Not sure where to put this? Any help is appreciated, thanks!!

  5. #5
    Junior Member
    Join Date
    Apr 2005
    Location
    Indonesia
    Posts
    1

    Mine is done use like this

    if u put that script in the component, u can change enough dtfReceivedDate whit this

    so ... like this:
    on (change) {
    this.dateFormatter = function(date){
    return d.getFullYear()+"/ "+(d.getMonth()+1)+"/ "+d.getDate();
    };

    }

  6. #6
    Junior Member
    Join Date
    Mar 2008
    Posts
    3

    Yes, you can format the Date of DateField Component

    Just copy and paste below code on your DateField Component.....

    on (change) {
    trace("Date on change !");
    this.dateFormatter = function(date){
    //return date.getFullYear()+"/ "+(date.getMonth()+1)+"/ "+date.getDate();
    return getMonthAsString(date.getMonth()+1)+" "+date.getDate()+", "+date.getFullYear();
    };
    function getMonthAsString(month:Number):String {
    var monthNames_array:Array = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
    return monthNames_array[month];
    }
    }

    It will show the Date in new format

  7. #7
    Junior Member
    Join Date
    Mar 2008
    Posts
    3
    Above code will show current Month +1 in Date Use below code........ to get current month in new format
    Last edited by garg; 03-20-2008 at 03:05 AM.

  8. #8
    Junior Member
    Join Date
    Mar 2008
    Posts
    3
    Quote Originally Posted by garg
    Just copy and paste below code on your DateField Component.....

    on(load) {
    this.dateFormatter = function(date){
    //return date.getFullYear()+"/ "+(date.getMonth()+1)+"/ "+date.getDate();
    return getMonthAsString(date.getMonth())+" "+date.getDate()+", "+date.getFullYear();
    };
    function getMonthAsString(month:Number):String {
    var monthNames_array:Array = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
    return monthNames_array[month];
    }
    this.selectedDate = new Date();
    }

    It will show the Date in new format
    Last edited by garg; 03-20-2008 at 03:19 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center