發表文章

目前顯示的是有「javascript」標籤的文章

Javascript 指定日期與現在時間相減

var strDate1 = "2000-10-25"; var now, s = ""; now = new Date(); now.setDate(now.getDate()); s += now.getYear()+"-"; s += (now.getMonth() + 101).toString().substring(1,3)+"-" ; s += (now.getDate()+ 100).toString().substring(1,3) ; strDate2 = s; strDate1=strDate1.replace(/-/g,"/"); strDate2=strDate2.replace(/-/g,"/"); var date1 = Date.parse(strDate1); var date2 = Date.parse(strDate2); if (Math.ceil((date2-date1)/(24*60*60*1000)) alert('你未满18岁'); } 這支Script可以在網頁檢查兩個日期是否相差18年整..