0
當我選擇一個日期說12/03/2014它回調Tue Dec 02 2014 16:00:00 GMT-0800(太平洋標準時間)前一天我輸入?使用Javascript返回來自輸入類型日期的不正確日期
<script>
function getAge() {
var today = new Date();
var birthDate = new Date(document.forms["name"]["birth"].value);
var age = today.getFullYear() - birthDate.getFullYear();
var m = today.getMonth() - birthDate.getMonth();
if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate()+1)) {
age--;
}
document.getElementById('age').innerHTML = birthDate;
}
</script>
<form name='name' onsubmit='return false'>
<input type="date" name="birth">
<p id='age'></p>
<button onclick='getAge()'>check</button>
</form>
這是一個時區問題。 – Barmar 2014-12-03 09:10:44
我在南非,當我運行代碼時,它給了我正確的選擇日期。 http://jsbin.com/luvolaboba/1/edit – user3811714 2014-12-03 09:24:07
哦,我看到謝謝 – Arthur 2014-12-03 09:26:51