转载者最起码注明作者和出处!http://www.cnblogs.com/GuominQiu
复制代码 代码如下:
//---------------------------------------------------------------------------
//判断日期格式是否正确
//返回值是错误信息, 无错误信息即表示合法日期字符串
function isDateString(strDate){
var strSeparator = "-"; //日期分隔符
var strDateArray;
var intYear;
var intMonth;
var intDay;
var boolLeapYear;
var ErrorMsg = ""; //出错信息
strDateArray = strDate.split(strSeparator);
//没有判断长度,其实2008-8-8也是合理的//strDate.length != 10 ||
if(strDateArray.length != 3) {
ErrorMsg += "日期格式必须为: yyyy-MM-dd";
return ErrorMsg;
}
intYear = parseInt(strDateArray[0],10);
intMonth = parseInt(strDateArray[1],10);
intDay = parseInt(strDateArray[2],10);
if(isNaN(intYear)||isNaN(intMonth)||isNaN(intDay)) {
ErrorMsg += "日期格式错误: 年月日必须为纯数字";
return ErrorMsg;
}
if(intMonth>12 || intMonth<1) {
ErrorMsg += "日期格式错误: 月份必须介于1和12之间";
return ErrorMsg;
}
if((intMonth==1||intMonth==3||intMonth==5||intMonth==7
||intMonth==8||intMonth==10||intMonth==12)
&&(intDay>31||intDay<1)) {
ErrorMsg += "日期格式错误: 大月的天数必须介于1到31之间";
return ErrorMsg;
}
if((intMonth==4||intMonth==6||intMonth==9||intMonth==11)
&&(intDay>30||intDay<1)) {
ErrorMsg += "日期格式错误: 小月的天数必须介于1到31之间";
return ErrorMsg;
}
if(intMonth==2){
if(intDay < 1) {
ErrorMsg += "日期格式错误: 日期必须大于或等于1";
return ErrorMsg;
}
boolLeapYear = false;
if((intYear%100) == 0){
if((intYear%400) == 0)
boolLeapYear = true;
}
else{
if((intYear % 4) == 0)
boolLeapYear = true;
}
if(boolLeapYear){
if(intDay > 29) {
ErrorMsg += "日期格式错误: 闰年的2月份天数不能超过29";
return ErrorMsg;
}
} else {
if(intDay > 28) {
ErrorMsg += "日期格式错误: 非闰年的2月份天数不能超过28";
return ErrorMsg;
}
}
}
return ErrorMsg;
}
标签:
日期格式

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com

P70系列延期,华为新旗舰将在下月发布

3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。

而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?

根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。