js根据生日计算是那一天

js计算生日是星期几,js根据生日计算是那一天码教程如下:

1.自定义月份:(1-12)

2.自定义天数:(1-31)

2.自定义年份:

计算:生日那天是星期几

js实现代码:

function MakeArray(n) {
this.length = n;
for (var i = 1; i <=n; i++) {
this[i] = 0;
}
}

//Initialize Days of Week Array
days = new MakeArray(7);
days[0] = "鏄熸湡鍏�"
days[1] = "鏄熸湡鏃�"
days[2] = "鏄熸湡涓€"
days[3] = "鏄熸湡浜�"
days[4] = "鏄熸湡涓�"
days[5] = "鏄熸湡鍥�"
days[6] = "鏄熸湡浜�"

//Initialize Months Array
months = new MakeArray(12);
months[1] = "涓€鏈�"
months[2] = "浜屾湀"
months[3] = "涓夋湀"
months[4] = "鍥涙湀"
months[5] = "浜旀湀"
months[6] = "鍏湀"
months[7] = "涓冩湀"
months[8] = "鍏湀"
months[9] = "涔濇湀"
months[10] = "鍗佹湀"
months[11] = "鍗佷竴鏈�"
months[12] = "鍗佷簩鏈�"

//Day of Week Function
function compute(form) {
var val1 = parseInt(form.day.value, 10)
if ((val1 < 0) || (val1 > 31)) {
alert("瓒呭嚭鑼冨洿浜嗭紒")
}
var val2 = parseInt(form.month.value, 10)
if ((val2 < 0) || (val2 > 12)) {
alert("浣犵殑鏈堜唤杈撳叆姝g‘锛�")
}
var val2x = parseInt(form.month.value, 10)
var val3 = parseInt(form.year.value, 10)
if (val3 < 1900) {
alert("浣犳湁杩欎釜宀佹暟锛�")
}
if (val2 == 1) {
val2x = 13;
val3 = val3-1
}
if (val2 == 2) {
val2x = 14;
val3 = val3-1
}
var val4 = parseInt(((val2x+1)*3)/5, 10)
var val5 = parseInt(val3/4, 10)
var val6 = parseInt(val3/100, 10)
var val7 = parseInt(val3/400, 10)
var val8 = val1+(val2x*2)+val4+val3+val5-val6+val7+2
var val9 = parseInt(val8/7, 10)
var val0 = val8-(val9*7)
form.result1.value = months[val2]+" "+form.day.value +"鏃�, "+form.year.value +"骞�"
form.result2.value = days[val0]
}

显示效果图:http://www.chinawe.net/tools/shengrijisuanqi/

参考文章:http://www.itmacom.com/jc/33451.html 

posted @ 2023-05-29 17:07  kaiser099  阅读(15)  评论(0编辑  收藏  举报