简体   繁体   中英

Datefield Ranges - Flex

I have two Datefields .Is there a way that i can set the date of second Datefield to a specified range(say three days ...?. I tried to do it but not worked .. dont know to convert date back to string and format it .. here is the code

<mx:DateField disabledRanges="{[{rangeEnd: new Date(2011,05,31)}]}" id="dfield1" change="leaveDate()" parseFunction="null" width="100"  x="156" y="130"/>
<mx:DateField disabledRanges="{[{rangeEnd: new Date(2011,05,31)}]}" id="dfield2"  parseFunction="null" width="100"  x="426" y="130"/>

private function leaveDate():void {
    //var dateLeave:Date = dfield1.selectedDate;
    var myTime:Date =dfield1.selectedDate;
    dateAdd("date", 3, myTime);
    //car formatter1:Datef
    commentField.text+=myTime+"\n"
    //dfield2.selectedDate = returnDate
}
public static function dateAdd(datepart:String = "", number:Number = 0, date:Date = null):Date
        {
    if (date == null) {
        date = new Date();
    }

    var returnDate:Date = new Date(date.time);;

    switch (datepart.toLowerCase()) {
        case "fullyear":
        case "month":
        case "date":
        case "hours":
        case "minutes":
        case "seconds":
        case "milliseconds":
            returnDate[datepart] += number;
            break;
        default:
            /* Unknown date part, do nothing. */
            break;
    }
      return returnDate;
}

It would be really grateful if somebody can help

To operate calculations on date, you must first convert them into numbers, ie dates in Epoch time or amount of seconds elapsed since january the first in 1970. Then, you can performa any operation on your date. For instance :

// Today
var today:Date = new Date();

// Tomorrow
var tomorrow:Date = new Date();

// How many seconds in a day ?
var secsInOneDay:Number = 60*60*24;

// Changes the tomorrow date to actually be tomorrow ^^
tomorrow.setTime(today.getTime() + secsInOneDay);

If you want to disable the dates prior to the date selected in dfield1 and the dates after three days after the date selected in dfield1 then try something like this:

<mx:DateField disabledRanges="{[{rangeEnd: new Date(2011,05,31)}]}" id="dfield1" change="leaveDate()" parseFunction="null" width="100"  x="156" y="130"/>
<mx:DateField disabledRanges="{[{rangeEnd: new Date(2011,05,31)}]}" id="dfield2"  parseFunction="null" width="100"  x="426" y="130"/>

private function leaveDate():void {
   dfield2.disabledRanges = [ { rangeEnd:new Date(
   dfield1.selectedDate.fullYear,
   dfield1.selectedDate.month,
   dfield1.selectedDate.date - 1 ) },
   { rangeStart:new Date(
   dfield1.selectedDate.fullYear,
   dfield1.selectedDate.month,
   dfield1.selectedDate.date + 3 ) } ];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM