WdatePicker时间控件联动选择

时间:2023-03-16 17:15:49
   $("#txtStartTime").bind("click focus", function () {
var endtimeTf = $dp.$('txtEndTime');
WdatePicker({
skin: dateSkin,
maxDate: '#F{$dp.$D(\'txtStartTime\')}',
dateFmt: "yyyy-MM-dd HH:mm:ss",
onpicked: function () { endtimeTf.focus(); }
});
});
$("#txtEndTime").bind("click focus", function () {
//这里设置了最大日期为当前日期,如果不需要则把maxDate:'%y-%M-%d'去掉
//WdatePicker({ skin: dateSkin, maxDate: '%y-%M-%d', minDate: '#F{$dp.$D(\'baojiakaishishijian\')}' });
WdatePicker({
skin: dateSkin,
minDate: '#F{$dp.$D(\'txtStartTime\')}',
dateFmt: "yyyy-MM-dd HH:mm:ss"
});
});

上面的可控制结束时间大于开始时间,可精确到秒

WdatePicker时间控件联动选择

===============================================================

下面的一个可控制结束时间在一周内

WdatePicker时间控件联动选择

 $("#txtStartTime").bind("click focus",
function() {
WdatePicker({
maxDate: "#F{$dp.$D('txtEndTime');}",
dateFmt: "yyyy-MM-dd HH:mm",
onpicked: function(Ag) {
var Ah = StrToDate(Ag.cal.getDateStr());
var Ai = StrToDate($("#txtEndTime").val());
var Af = Ai.dateDiff(Ah, "d");
if (Af > 7) {
$("#txtEndTime").val(Ah.DateAdd("d", 7).format("yyyy-MM-dd HH:mm"))
}
}
})
});
$("#txtEndTime").bind("click focus",
function() {
WdatePicker({
minDate: "#F{$dp.$D('txtStartTime')}",
maxDate: "#F{$dp.$D('txtStartTime',{d:7});}",
dateFmt: "yyyy-MM-dd HH:mm"
})
});
WdatePicker({
eCont: "DataControl",
onpicked: function(Af) {
$("#starOption").fadeOut();
$("#txtStartTime").val(Af.cal.getDateStr() + " 00:00");
$("#txtEndTime").val(Af.cal.getDateStr() + " 23:59");
if ($("#selCarBrand_hidden").length > 0 && $.trim($("#selCarBrand_hidden").val()) != "") {
v(true)
}
}
});
 Date.prototype.format = function(A) {
var B = {
"M+": this.getMonth() + 1,
"d+": this.getDate(),
"h+": this.getHours(),
"H+": this.getHours(),
"m+": this.getMinutes(),
"s+": this.getSeconds(),
"q+": Math.floor((this.getMonth() + 3) / 3),
"S": this.getMilliseconds()
};
if (/(y+)/.test(A)) {
A = A.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length))
}
for (var C in B) {
if (new RegExp("(" + C + ")").test(A)) {
A = A.replace(RegExp.$1, RegExp.$1.length == 1 ? B[C] : ("00" + B[C]).substr(("" + B[C]).length))
}
}
return A
};
Date.prototype.dateDiff = function(C, D) {
var B = 1;
if (!C) {
return "必须是日期对象"
}
var A = this.getTime() - C.getTime();
switch (D) {
case "ms":
B = 1;
break;
case "s":
B = 1000;
break;
case "m":
B = 60 * 1000;
break;
case "h":
B = 60 * 60 * 1000;
break;
case "d":
B = 24 * 60 * 60 * 1000;
break
}
return Math.floor(A / B)
};
Date.prototype.DateAdd = function(C, A) {
var B = this;
switch (C) {
case "s":
return new Date(Date.parse(B) + (1000 * A));
case "m":
return new Date(Date.parse(B) + (60000 * A));
case "h":
return new Date(Date.parse(B) + (3600000 * A));
case "d":
return new Date(Date.parse(B) + (86400000 * A));
case "w":
return new Date(Date.parse(B) + ((86400000 * 7) * A));
case "q":
return new Date(B.getFullYear(), (B.getMonth()) + A * 3, B.getDate(), B.getHours(), B.getMinutes(), B.getSeconds());
case "M":
return new Date(B.getFullYear(), (B.getMonth()) + A, B.getDate(), B.getHours(), B.getMinutes(), B.getSeconds());
case "y":
return new Date((B.getFullYear() + A), B.getMonth(), B.getDate(), B.getHours(), B.getMinutes(), B.getSeconds())
}
return B
};
Date.prototype.Init = function(A) {
return new Date(A.replace(/-/g, "/"))
};
Date.StrToDate = function(A) {
return new Date(A.replace(/-/g, "/"))
};
Date.FormatTime = function(A) {
var H = "";
A = Math.round(A);
var B = A % 60;
if (B > 0) {
H = B + "秒";
A -= B
}
if (A >= 60) {
var J = A / 60;
var E = J % 60;
J -= E;
H = E + "分" + H;
if (J >= 60) {
var I = J / 60;
var C = I % 24;
I -= C;
H = C + "时" + H;
if (I >= 24) {
var L = I / 24;
var G = L % 30;
H = G + "天" + H;
L -= G;
if (L >= 30) {
var F = L / 30;
var D = F % 12;
H = D + "月" + H;
F -= D;
if (F >= 12) {
var K = F / 12;
H = K + "年" + H
}
}
}
}
}
return H
};
function StrToDate(A) {
return new Date(A.replace(/-/g, "/"))
}