开发者

Datefield Ranges - Flex

开发者 https://www.devze.com 2023-04-09 20:37 出处:网络
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

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, i.e. 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 ) } ];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号