//获取前几天
getDay: function (day) {
var myDate = new Date(); //获取今天日期
myDate.setDate(myDate.getDate() - (day - 1));//setDate() 方法用于设置一个月的某一天。
var dateArray = [];
var dateTemp;
var flag = 1;
for (var i = 1; i < day; i++) {
dateTemp = myDate.getDate() + '日';
dateArray.push(dateTemp);
myDate.setDate(myDate.getDate() + flag);
}
dateArray.push(myDate.getDate()+ '日');
return dateArray;
},
//获取前几个月
GetMonthArr: function (day) {
var self = this;
var date = new Date(),
arr = [];
var month = date.getMonth() + 1;
for (var i = 0; i < day; i++) {
arr.push(month + "月");
if (month-- == 1) {
month = 12;
}
}
return arr.reverse();
},
//获取当前日期时间
timeFun: function () {
var date = new Date();
var seperator1 = "/";
var seperator2 = ":";
var month = date.getMonth() + 1;
var strDate = date.getDate();
var hours = date.getHours();
var minutes = date.getMinutes();
var seconds = date.getSeconds();
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
this.date = strDate;
}
if (hours >= 0 && hours <= 9) {
hours = "0" + hours;
}
if (minutes >= 0 && minutes <= 9) {
minutes = "0" + minutes;
}
if (seconds >= 0 && seconds <= 9) {
seconds = "0" + seconds;
}
//到日期
this.nowDateTime = date.getFullYear() + '年' + month + '月' + strDate + '日';
//到时分秒
this.nowTime = date.getFullYear() + seperator1 + month + seperator1 + strDate + " " + hours + seperator2 + minutes + seperator2 + seconds;
},
js获取当前时间,前7天日期数组,前7个月的时间
最新推荐文章于 2024-01-30 16:43:04 发布