獲取日期:昨天,前臺,明天,後天,獲取前幾天或後幾天
阿新 • • 發佈:2018-12-14
1.引數
num:該引數為數字,為正數就是當前日期天數往後移的天數,比如正數1就是明天,-1就是昨天
str:日期中間的間隔符,輸入'-'就為'YYYY-MM-DD',或輸入'/'就為'YYYY/MM/DD'
function getDay(num, str) { var today = new Date(); var nowTime = today.getTime(); var ms = 24*3600*1000*num; today.setTime(parseInt(nowTime + ms));var oYear = today.getFullYear(); var oMoth = (today.getMonth() + 1).toString(); if (oMoth.length <= 1) oMoth = '0' + oMoth; var oDay = today.getDate().toString(); if (oDay.length <= 1) oDay = '0' + oDay; return oYear + str + oMoth + str + oDay; }