var date = getDate (1); //前一天,如果传3就是前三天
$('#test1').val(date.passday);
function getDate (num) {
var nowDate = new Date();
var nowYear = nowDate.getFullYear();
var nowMonth = nowDate.getMonth();
var nowDay = nowDate.getDate();
var nowHours = nowDate.getHours();
var nowMinutes = nowDate.getMinutes();
var nowSeconds = nowDate.getSeconds();
var passDate = new Date(nowYear, nowMonth, nowDay - num + 1, 0, 0, 0); //前几天
var passThreeDate = new Date(nowYear, nowMonth-3, nowDay + 1, 0, 0, 0); //前3个月
var passYear = passDate.getFullYear();
var passMonth = passDate.getMonth();
var passThreeMonth = passThreeDate.getMonth()+1; //前3个月
var passDay = passDate.getDate();
var passHours = passDate.getHours();
var passMinutes = passDate.getMinutes();
var passSeconds = passDate.getSeconds();
var beforeMonth = nowMonth; //前一个月
var nowMonthNew = nowMonth+1; //当月
var passMonthNew = passMonth+1;
if(nowMonth < 10){
nowMonthNew = "0" + ''+ nowMonthNew;
beforeMonth = "0" + ''+ nowMonth;
}
if(nowDay < 10) nowDay = "0" + '' + nowDay;
if(nowHours < 10) nowHours = "0" + '' + nowHours;
if(nowMinutes < 10) nowMinutes = "0" + '' + nowMinutes;
if(nowSeconds < 10) nowSeconds = "0" + '' + nowSeconds;
if(passDay < 10) passDay = "0" + '' + passDay;
if(passMonth < 10) passMonthNew = "0" + ''+ passMonthNew;
if(passThreeMonth < 10) passThreeMonth = "0" + ''+ passThreeMonth;
if(passHours < 10) passHours = "0" + '' + passHours;
if(passMinutes < 10) passMinutes = "0" + '' + passMinutes;
if(passSeconds < 10) passSeconds = "0" + '' + passSeconds;
return {
nowday: nowYear + '-' + nowMonthNew + '-' + nowDay + ' ' + nowHours + ':' + nowMinutes + ':' + nowSeconds,
passday: passYear + '-' + passMonthNew + '-' + passDay + ' ' + passHours + ':' + passMinutes + ':' + passSeconds,
nowDayDate:nowYear + '-' + nowMonthNew + '-' + nowDay,
threeDayBefore: nowYear + '-' + nowMonthNew + '-' + passDay,
nowMonthDate:nowYear + '' + beforeMonth,
threeMonthBefore: nowYear + '' + passThreeMonth
}
}
阅读(670) | 评论(0) | 转发(0) |