您的位置:首页 > Web前端 > JavaScript

EXTJS 开始日期和开始时间,结束日期和结束时间,当前日期和当前时间之间的比较

2017-06-01 16:52 489 查看
{
columnWidth : .5,
layout : 'form',
border : false,
items : [{
xtype : 'datefield',
fieldLabel : '结束日期',
format : 'Y-m-d',
allowBlank : true,
name : 'warnenddate',
id:'enddate',
//vtype: 'daterange', // 调用的 验证方法
//startDateField: 'begindate', // 设置开始时间
maxLength : '20',
anchor : '90%',
listeners:{
"select":function(){
var bd = Ext.getCmp('begindate').getValue();
var ed = Ext.getCmp('enddate').getValue();
var bdd  = Date.parse(bd); //Date.parse的处理很关键
var edd = Date.parse(ed);
var myDate = new Date();
var year = myDate.getFullYear();
var month = myDate.getMonth()+1;
var day = myDate.getDate();
var now = year+"/"+month+"/"+day;
//alert(now);
var xdd = Date.parse(now);//变为毫秒
//alert(xdd);
if(bd==""||bdd=="NaN"){
var config = {
title:'提示',
msg: '请选择开始日期!'
}
Ext.Msg.show(config);

var bd=Ext.getCmp("enddate");
bd.setValue(" ");
return false;
}else{
if(edd>=xdd){
if(edd>=bdd){
return true;
}else{
var config = {
title:'提示',
msg: '开始日期不能大于结束日期!'
}
Ext.Msg.show(config);

var bd=Ext.getCmp("enddate");
bd.setValue(" ");
return false;
}

}else{
var config = {
title:'提示',
msg: '当前日期不能大于结束日期!'
}
Ext.Msg.show(config);

var bd=Ext.getCmp("enddate");
bd.setValue(" ");
return false;
}
}

}

}
}]
}, {
columnWidth : .5,
layout : 'form',
border : false,
items : [{
xtype : 'timefield',
fieldLabel : '结束时间',
format : 'G:i:s',
allowBlank : true,

4000
name : 'warnendtime',
id:'endtime',
maxLength : '8',
anchor : '90%',
listeners:{
"select":function(){
var bd = Ext.getCmp('begindate').getValue();
var bdd = Date.parse(bd);//变为毫秒
var ed = Ext.getCmp('enddate').getValue();
var edd = Date.parse(ed);//变为毫秒
var myDate = new Date();
var year = myDate.getFullYear();
var month = myDate.getMonth()+1;
var day = myDate.getDate();
var now = year+"/"+month+"/"+day;
var xdd = Date.parse(now);//变为毫秒

if(ed==""||edd=="NaN"){
var config = {
title:'提示',
msg: '请先选择结束日期!'
}
Ext.Msg.show(config);
var tt=Ext.getCmp("endtime");
tt.setValue(" ");
return flase;
}
else{
if(xdd==edd){
var bt = Ext.getCmp('begintime').getValue(); //开始时间
var et = Ext.getCmp('endtime').getValue(); //结束时间
var myDate = new Date();
var year = myDate.getFullYear();
var month = myDate.getMonth()+1;
var day = myDate.getDate();
var now = year+"/"+month+"/"+day;

var xt= myDate.getTime();
if(bt==""||bt==null){
var config = {
title:'提示',
msg: '请选择开始时间!'
}
Ext.Msg.show(config);
var tt=Ext.getCmp("endtime");
tt.setValue(" ");
return false;
}
bt= Date.parse(now +" "+ bt);
et= Date.parse(now +" "+ et);
if (et>xt) {
if(bdd==edd){
var bt = Ext.getCmp('begintime').getValue(); //开始时间
if(bt==""||bt==null){
var config = {
title:'提示',
msg: '请选择开始时间!'
}
Ext.Msg.show(config);
var tt=Ext.getCmp("endtime");
tt.setValue(" ");
return false;
}
var et = Ext.getCmp('endtime').getValue(); //结束时间
var myDate = new Date();
var year = myDate.getFullYear();
var month = myDate.getMonth()+1;
var day = myDate.getDate();
var now = year+"/"+month+"/"+day;
bt= Date.parse(now +" "+ bt);
et= Date.parse(now +" "+ et);
if (et>bt) {
return true;
}else if(et<bt){
var config = {
title:'提示',
msg: '结束时间不能小于开始时间!'
}
Ext.Msg.show(config);
var tt=Ext.getCmp("endtime");
tt.setValue(" ");
return false;
}else{
var config = {
title:'提示',
msg: '结束时间不能等于开始时间!'
}
Ext.Msg.show(config);
var tt=Ext.getCmp("endtime");
tt.setValue(" ");
return false;
}
}else if(edd>bdd){
var bt = Ext.getCmp('begintime').getValue(); //开始时间
if(bt==""||bt==null){
var config = {
title:'提示',
msg: '请选择开始时间!'
}
Ext.Msg.show(config);
var tt=Ext.getCmp("endtime");
tt.setValue(" ");
return false;
}
return true;
}
}else if(et<xt){
var config = {
title:'提示',
msg: '结束时间不能小于当前时间!'
}
Ext.Msg.show(config);

var tt=Ext.getCmp("endtime");
tt.setValue(" ");
return false;

}else{
var config = {
title:'提示',
msg: '结束时间不能等于当前时间!'
}
Ext.Msg.show(config);
var tt=Ext.getCmp("endtime");
tt.setValue(" ");
return false;
}

}else if(edd>xdd){
var bt = Ext.getCmp('begintime').getValue(); //开始时间
if(bt==""||bt==null){
var config = {
title:'提示',
msg: '请选择开始时间!'
}
Ext.Msg.show(config);
var tt=Ext.getCmp("endtime");
tt.setValue(" ");
return false;
}
return true;

}

}
}

}
}]
}]
}

开始日期和开始时间不能在结束日期和结束时间之后,还得跟当前日期和当前时间比较,重点在逻辑
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐