JavaScript日期格式判断

function isDate(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]);
}
function GetNewDate(str) {
var dependedVal = str;
//根据日期字符串转换成日期
var regEx = new RegExp("\\-", "gi");
dependedVal = dependedVal.replace(regEx, "/");
//dependedVal=dependedVal.replace("\\-","/");//这样不行
//alert(dependedVal)
//parse 需要 2005/3/4 这种格式!法克!
var milliseconds = Date.parse(dependedVal);
//alert(milliseconds)
var dependedDate = new Date();
dependedDate.setTime(milliseconds);

return dependedDate;
}