/**
* 验证日期格式:yyyy-MM-dd hh:mm:ss
*
* @author deng-j
* @param date
* @returns right:true,wrong:false
*/
function strDateTime(str) {
var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/;
var r = str.match(reg);
if(r==null)return false;
var d= new Date(r[1], r[3]-1,r[4],r[5],r[6],r[7]);
return (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]&&d.getHours()==r[5]&&d.getMinutes()==r[6]&&d.getSeconds()==r[7]);
}
/**
* 验证日期格式
*
* @param date
* @returns right:true,wrong:false
*/
function checkDateFormat(date) {
if (date.length > 0) {
var re = new RegExp(/((^((1[8-9]\d{2})|([2-9]\d{3}))(-)(10|12|0?[13578])(-)(3[01]|[12][0-9]|0?[1-9])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(-)(11|0?[469])(-)(30|[12][0-9]|0?[1-9])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(-)(0?2)(-)(2[0-8]|1[0-9]|0?[1-9])$)|(^([2468][048]00)(-)(0?2)(-)(29)$)|(^([3579][26]00)(-)(0?2)(-)(29)$)|(^([1][89][0][48])(-)(0?2)(-)(29)$)|(^([2-9][0-9][0][48])(-)(0?2)(-)(29)$)|(^([1][89][2468][048])(-)(0?2)(-)(29)$)|(^([2-9][0-9][2468][048])(-)(0?2)(-)(29)$)|(^([1][89][13579][26])(-)(0?2)(-)(29)$)|(^([2-9][0-9][13579][26])(-)(0?2)(-)(29)$))/);
if (!re.test(date)) {
return false;
}
return true;
}
return true;
}
/**
* 按月份查询当前日期的前后几个月的时间
*
* @param date_from (前几个)月份
* @param date_to (后几个)月份
* @param input_from 日期查询输入文本(从)
* @param input_to 日期查询输入文本(到)
* @param format 日期格式,默认yyyy-MM-dd
*/
function setDateInterval(date_from, date_to, input_from, input_to, format) {
if (format == null || format == "") {
format = "yyyy-MM-dd";
}
var fromDate = new Date();
// 前几个月
fromDate.setMonth(fromDate.getMonth() - date_from);
var fromTime = fromDate.format(format);
// 文本赋值
Ext.getDom(input_from).value = fromTime;
if (date_to != 'undefined' && date_to != 0) {
var toDate = new Date();
// 后几个月
toDate.setMonth(toDate.getMonth() + date_to);
var toTime = toDate.format(format);
// 文本赋值
Ext.getDom(input_to).value = toTime;
}
return [fromTime, toTime];
}