前端校验日期选择是否有效,且转换日期格式为YYYY-MM-dd
- //对日期进行转化格式 YYYY-MM-DD
function getNowFormatDate() {
date = new Date(); //获取系统当前日期
var seperator1 = “-”;
var year = date.getFullYear();
var month = date.getMonth() + 1;
var strDate = date.getDate();
if (month >= 1 && month <= 9) {
month = “0” + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = “0” + strDate;
}
currentdate = year + seperator1 + month + seperator1 + strDate;
return currentdate; //将系统当前日期进行转化,转化为yyyy-mm-dd
} - //日期比较函数
function StringToDate(Str)
{
return new Date(Str.replace(/-/,”/“));
} - 在调用时:加入判断
if(StringToDate(currentdate)<StringToDate(rateTime)){ //获取当前时间和之前的时间进行比较
$(“#datePercent”).val(“请输入合法日期”);
}else{
rateMapFun(rateTime,null);
}
还没有评论,来说两句吧...