|
|
function strDateTime1(str){
|
|
|
var reg = /^(\d{1,4})(-|\/)(\d{1,2})\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]);
|
|
|
var newStr=d.getFullYear()+r[2]+(d.getMonth()+1)+r[2]+d.getDate()
|
|
|
return newStr==str
|
|
|
}
|
|
|
//alert(strDateTime("2002-1-31"))
|
|
|
//alert(strDateTime("2002-1-41"))
|
|
|
|
|
|
|
|
|
function strDateTime2(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]);
|
|
|
var newStr=d.getFullYear()+r[2]+(d.getMonth()+1)+r[2]+d.getDate()+" "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds()
|
|
|
return newStr==str
|
|
|
}
|
|
|
//alert(strDateTime("2002-1-31 12:34:56"))
|
|
|
//alert(strDateTime("2001-2-29 12:54:56"))
|
|
|
//alert(strDateTime("2002-1-41 12:00:00"))
|
|
|
|
|
|
|
|
|
var s="2002-4-16"
|
|
|
//alert(chkDate(s));
|
|
|
function chkDate3(sDate){
|
|
|
var r=/\d{4}(?:-\d{1,2}){0,2}/
|
|
|
//正则表达式,判断是否为yyyy-mm-dd,yyyy-mm,yyyy格式
|
|
|
if(sDate.match(r)==sDate){
|
|
|
var arr=sDate.split("-")
|
|
|
switch(arr.length){
|
|
|
//根据不同的yyyy-mm-dd,yyyy-mm格式判断年月日数字是否正确
|
|
|
case 3:
|
|
|
var tmpDate=new Date(arr[0],arr[1],arr[2]);
|
|
|
if(tmpDate.getMonth()==arr[1] && tmpDate.getFullYear()==arr[0]) return true;
|
|
|
break;
|
|
|
case 2:
|
|
|
if(arr[1]<13) return true;
|
|
|
break;
|
|
|
default:
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
|
|
|
/*
|
|
|
时间有效性判断函数
|
|
|
All by happywinds
|
|
|
*/
|
|
|
function verifyDate(textObj)
|
|
|
{
|
|
|
var str=textObj;
|
|
|
textObj = textObj.replace(/\s+/g,"");
|
|
|
if(str.search(/^\d{4}-\d{1,2}-\d{1,2}$/) == 0)
|
|
|
{
|
|
|
var y = parseInt(str.split("-")[0]);
|
|
|
var m = parseInt(str.split("-")[1]);
|
|
|
var d = parseInt(str.split("-")[2]);
|
|
|
switch(m)
|
|
|
{
|
|
|
case 1:
|
|
|
case 3:
|
|
|
case 5:
|
|
|
case 7:
|
|
|
case 8:
|
|
|
case 10:
|
|
|
case 12:
|
|
|
if(d>31)
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
break;
|
|
|
case 2:
|
|
|
if((y%4==0 && d>29) || ((y%4!=0 && d>28)))
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
break;
|
|
|
case 4:
|
|
|
case 6:
|
|
|
case 9:
|
|
|
case 11:
|
|
|
if(d>30)
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
break;
|
|
|
default:
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//+---------------------------------------------------
|
|
|
//| 取得当前日期所在月的最大天数
|
|
|
//+---------------------------------------------------
|
|
|
function getDaysInMonth(year,month)
|
|
|
{
|
|
|
month = parseInt(month,10)+1;
|
|
|
var temp = new Date(year+"/"+month+"/0");
|
|
|
return temp.getDate();
|
|
|
}
|
|
|
|
|
|
|
|
|
|