//预产期&四维时间计算器 function testYZ() { if (document.health.year.value == "" || document.health.month.value == "" || document.health.day.value == "") { alert("请填写完整年月日!"); return false; } if (document.health.year.value > 2050 || document.health.year.value < 1990) { alert("请填写正确年份!"); document.health.year.focus(); return false; } if (document.health.month.value > 12 || document.health.month.value < 1) { alert("请填写正确月份!"); document.health.month.focus(); return false; } if (document.health.day.value > 31 || document.health.day.value < 1) { alert("请填写正确日子!"); document.health.day.focus(); return false; } if (!isDate(document.health.year.value, document.health.month.value, document.health.day.value)) { alert("年月日组合有错,请重新填写!"); return false; } function isDate(year, month, day) { // month argument must be in the range 1 - 12 month = month - 1; // javascript month range : 0- 11 var tempDate = new Date(year, month, day); if ((year2k(tempDate.getFullYear()) == year) && (month == tempDate.getMonth()) && (day == tempDate.getDate())) { return true; } else { return false; } } function year2k(d) { return (d < 1000) ? d + 1900 : d; } var m = parseInt(document.health.month.value,10)-1; var stime = new Date(document.health.year.value,m,parseInt(document.health.day.value,10)); var yuchan2 = new Date(document.health.year.value,m,parseInt(document.health.day.value,10)); var tail=[health.year.value,health.month.value,health.day.value]; tail=(new Date(tail.join('/'))).getTime();////你的末次月经时间的毫秒表示 //将末次月经第一天+平均月经周期天数+252天 var ycq=new Date(tail+(30+252)*86400000);//预产期日期 var tailmon=ycq.getMonth()+1; var nowt = new Date(); var nowtime = nowt.getTime(); var chatime = nowtime - Date.parse(stime); var chaweek = Math.floor((chatime) / (1000 * 60 * 60 * 24 * 7)); var ccday = chaweek*7; if (chaweek < 3) chaweek = 0; if (chaweek > 43) alert("亲,您的预产期已经过了!"); var days; var days1; if (chaweek < 42 && chaweek > 0){ days = 133; days1 = 85; } if (chaweek < 30 && chaweek > 28){ days = 91; days1 = 71; } if (chaweek > 43 || chaweek == 0){ days = 0; days1 = 0; } if (chaweek == 0){ $(".date").text(" "); $(".date1").text("亲,您还没有怀孕吧!"); }else if(chaweek>43){ $(".date").text(" "); $(".date1").text("亲,您的预产期已经过了!"); }else{ $(".date").text(ccday); $(".date1").text(ycq.getFullYear() +"年"+tailmon +"月"+ycq.getDate() +"日"); } } Date.prototype.format = function(format) { var o ={ 'M+' : this.getMonth()+1, //month 'd+' : this.getDate(), //day 'h+' : this.getHours(), //hour 's+' : this.getSeconds(), //second 'm+' : this.getMinutes(), //minute 'q+' : Math.floor((this.getMonth()+3)/3), //quarter 'S' : this.getMilliseconds() //millisecond }; if(/(y+)/.test(format)){format=format.replace(RegExp.$1,(this.getFullYear()+'').substr(4 - RegExp.$1.length));} for(var k in o){ if(new RegExp('('+ k +')').test(format)){format = format.replace(RegExp.$1,RegExp.$1.length==1 ? o[k] : ('00'+ o[k]).substr((''+ o[k]).length));}} return format; };