话不多说直接写放代码
/**
* 获取当前日期以及本月的第一天
*/
function getBeginTime() {
var now = new Date();
now.setDate(1);
return getFormatDate(now) + " 00:00:00";
}
function getNowDate() {
var now = new Date();
return getFormatDate(now) + " 23:59:59";
}
//获取30天以前
function getOneMonthAgoDate() {
var now = new Date();
var time = now.getTime()-1000*60*60*24*30
var lastDate= new Date(time);
return getFormatDate(lastDate) + " 00:00:00";
}
function getFormatDate(srcdate) {
var formatDate = "";
//初始化时间
var Year = srcdate.getFullYear(); //ie火狐下都可以
var Month = srcdate.getMonth() + 1;
formatDate += Year;
if (Month >= 10) {
formatDate += "-" + Month;
} else {
formatDate += "-0" + Month;
}
var Day = srcdate.getDate();
if (Day >= 10) {
formatDate += "-" + Day;
} else {
formatDate += "-0" + Day;
}
/*var Hour = srcdate.getHours();
if (Hour >= 10) {
formatDate += " " + Hour;
} else {
formatDate += " 0" + Hour;
}
var Minute = srcdate.getMinutes();
if (Minute >= 10) {
formatDate += ":" + Minute;
} else {
formatDate += ":0" + Minute;
}
var Second = srcdate.getSeconds();
if (Second >= 10) {
formatDate += ":" + Second;
} else {
formatDate += ":0" + Second;
}*/
return format