DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> 關於JavaScript >> 如何使用Javascript獲取距今n天前的日期
如何使用Javascript獲取距今n天前的日期
編輯:關於JavaScript     
本篇文章是對使用Javascript獲取距今n天前日期的實現代碼進行了詳細的分析介紹,需要的朋友參考下   復制代碼 代碼如下:


 function Test(day) {
                var today = new Date();
                var beforMilliseconds = today.getTime() - 1000 * 3600 * 24 * day;
                var beforday = new Date();
                beforday.setTime(beforMilliseconds);
                var strYear = beforday.getFullYear();
                var strDay = beforday.getDate();
                var strMonth = beforday.getMonth() + 1;
                if (strMonth < 10) {
                    strMonth = "0" + strMonth;
                }
                var strYesterday = strYear + "-" + strMonth + "-" + strDay;
                alert(strYesterday);
            }

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved