js處理日期的一些整理(js擷取給定日期前一天的日期)

來源:互聯網
上載者:User

標籤:style   blog   color   io   ar   sp   div   on   cti   

 var date = new Date(); alert(date);//擷取目前時間
 alert(date.getFullYear());//擷取當前年分
 alert(date.getMonth());//擷取月份(擷取當前月份要加1)
 alert(date.getDate());//擷取當前日期的幾號
 alert(date.getDay());//擷取當前是星期幾
 alert(date.getTime());//擷取距離1970/01/01 至今的毫秒
settime()是向 1970/01/01 08:00:00 添加毫秒,並顯示新的日期和時間。
var
date = new Date();
date.setTime(
24*1000*60*60);document.write(date);//輸出Thu Jan 02 1970 08:00:00 GMT+0800 (China Standard Time)
//擷取指定日期後幾天(明天)的日期   d是那一天,i是後幾天
function getTomorrow(d, i) {
var date = new Date(d); var tomorrow_milliseconds = date.getTime() + 1000 * 60 * 60 * 24 * i; var tomorrow= new Date(); tomorrow.setTime(tomorrow_milliseconds); var strYear = tomorrow.getFullYear(); var strDay = tomorrow.getDate(); var strMonth = tomorrow.getMonth() + 1; if (strMonth < 10) { strMonth = "0" + strMonth; } datastr = strYear + "/" + strMonth + "/" + strDay; return datastr; }
//擷取給定日期前幾天的日期i傳負數即可

 

js處理日期的一些整理(js擷取給定日期前一天的日期)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.