日期字段范围 - Flex
我有两个日期字段。有没有一种方法可以将第二个日期字段的日期设置为指定范围(比如说三天......?我尝试这样做但没有成功......不知道将日期转换回字符串并且格式化它..这是代码
<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;
}
如果有人可以提供帮助,我将非常感激
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要对日期进行计算,您必须首先将它们转换为数字,即大纪元时间中的日期或自 1970 年 1 月 1 日以来经过的秒数。然后,您可以对日期执行任何操作。例如 :
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 :
如果您想禁用 dfield1 中所选日期之前的日期以及 dfield1 中所选日期三天后的日期,请尝试如下操作:
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: