2007年8月31日 星期五

JavaScript 找前一天日期

<SCRIPT language="javascript">
function addDate(dd,dadd){
var a = new Date(dd)
a = a.valueOf()
a = a + dadd * 24 * 60 * 60 * 1000
a = new Date(a)
return a;
}

//抓取現在日期

var now = new Date();
var years = now.getYear();
var months = now.getMonth()+1;
var days = now.getDate();
var hours = now.getHours();

//抓取前一天日期

NextNow = addDate(months+"/"+days+"/"+years,-1);
years = NextNow.getYear();
months = NextNow.getMonth()+1;
days = NextNow.getDate();

alert("前一天日期:"+years+"年"+months+"月"+days+"日");

</SCRIPT>

沒有留言: