年齢 = floor((今日-誕生日)/10000)で計算できる
ということで、下記のように計算したところ、
結果が-63377780 と表示されてしまい、年齢計算ができません
何が悪いのでしょうか。。
js
1 2alert(calcAge( new Date( "1990" , "1" , "1", '00','00','00') )); 3 4 // 年齢計算関数 5function calcAge(birthdate) { 6 var today = new Date(); 7 targetdate = today.getFullYear() * 10000 + (today.getMonth() + 1) * 100 + today.getDate(); 8 return (Math.floor((targetdate - birthdate) / 10000)); 9} 10 11
回答2件
あなたの回答
tips
プレビュー