当年啥都不懂,写个比较Date的函数,用了最蠢的办法:
- /**
- * 时间验证函数
- * */
- protected function checkingDate( firstDate:String, secDate:String):Boolean
- {
- if(int(firstDate.substr(0,4))>int(secDate.substr(0,4)))
- {
- AlertUtil.AlertShow("日期范围有误,请确保结束日期在开始日期之后","错误提示",Alert.OK, this,null,3);
- return false;
- }
- else if(int(firstDate.substr(5,2))>int(secDate.substr(5,2)))
- {
- AlertUtil.AlertShow("日期范围有误,请确保结束日期在开始日期之后","错误提示",Alert.OK, this,null,3);
- return false;
- }
- else if(int(firstDate.substr(8,2))>int(secDate.substr(8,2)))
- {
- AlertUtil.AlertShow("日期范围有误,请确保结束日期在开始日期之后","错误提示",Alert.OK, this,null,3);
- return false;
- }
- return true;;
-
- }
后面突然发现有现成的封装好的函数调用可以用来实现,而且用户友好性更强
- xmlns:s="library://ns.adobe.com/flex/spark"
- xmlns:mx="library://ns.adobe.com/flex/mx"
- creationComplete="init(event)"
- width="100%" height="100%">
-
-
-
- import mx.events.CalendarLayoutChangeEvent;
- import mx.events.FlexEvent;
- import mx.utils.ObjectUtil;
-
-
- //-----------------------属性 end------------------------
-
-
-
- //-----------------------初始化-----------------------------
-
- /**初始化函数*/
- protected function init(event:FlexEvent):void
- {
- //设置开始日期默认为1月1日
- var date:Date=new Date();
- datefld_ksrq.selectedDate= new Date (date.getFullYear()-1, 0, 1);
- datefld_jsrq.selectedDate= new Date ();
-
- }
-
- //-----------------------初始化 end-----------------------
-
- //-----------------------组件事件响应-----------------------------
-
- /**btnQuery按钮单击事件处理函数
- */
-
- /**datefld_ksrq日期控件事件处理函数
- */
- protected function datefld_ksrq_changeHandler(event:CalendarLayoutChangeEvent):void
- {
- if(ObjectUtil.dateCompare(event.currentTarget.selectedDate,datefld_jsrq.selectedDate)>0){
-
- var cDateObject:Object={rangeStart:event.currentTarget.selectedDate,rangeEnd:null};
- this.datefld_jsrq.selectableRange=cDateObject;
- this.datefld_jsrq.selectedDate=event.currentTarget.selectedDate;
- }
- else
- {
- cDateObject={rangeStart:event.currentTarget.selectedDate,rangeEnd:null};
- this.datefld_jsrq.selectableRange=cDateObject;
- }
-
- }
-
- /**datefld_jsrq日期控件事件处理函数
- */
- protected function datefld_jsrq_changeHandler(event:CalendarLayoutChangeEvent):void
- {
-
- if(ObjectUtil.dateCompare(event.currentTarget.selectedDate,datefld_ksrq.selectedDate)<0){
- this.datefld_ksrq.selectedDate=event.currentTarget.selectedDate;
- }
-
- }
-
- //-----------------------组件事件响应 end-----------------------
-
-
- ]]>
-
-
-
-
-
-
-
- change="datefld_ksrq_changeHandler(event)" enabled="true"
- formatString="YYYY-MM-DD" textAlign="center" yearNavigationEnabled="true"/>
-
-
- change="datefld_jsrq_changeHandler(event)" enabled="true"
- formatString="YYYY-MM-DD" showToday="true" textAlign="center"
- yearNavigationEnabled="true"/>
-
-
-
-
网上看到了一些比较Date的方法,摘过来,貌似比我的简单~~学习~没验证过
1. ObjectUtil.dateCompare(date1,date2)
2. ObjectUtil.dateCompare(date1,date2) 返回值为int类型
date1 > date2 1
date1 = date2 0
date1 < date2 -1
3. 自定义方法
/* 比较两个日期大小 */
public static function compare(date1:Date, date2:Date):int {
if (Number(date1) < Number(date2)) {
return -1
}
if (Number(date1) == Number(date2)) {
return 0;
}
return 1;
}
阅读(571) | 评论(0) | 转发(0) |