function getLastMonth() {
var now = new Date();
var year = now.getFullYear();
var month = now.getMonth() + 1;
var day = now.getDate();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
var dateObj = {};
hours = hours < 10 ? '0' + hours: hours;
minutes = minutes < 10 ? '0' + minutes: minutes;
seconds = seconds < 10 ? '0' + seconds: seconds;
dateObj.now = year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;
var nowMonthDay = new Date(year, month, 0).getDate();
if (month - 1 <= 0) {
dateObj.last = year -1 + "-" + 12 + "-" + day;
} else {
var lastMonthDay = new Date(year, parseInt(month) - 1, 0).getDate();
if (lastMonthDay < day) {
if (day < nowMonthDay) {
dateObj.last = year + "-" + (month - 1) + "-" + (lastMonthDay - (nowMonthDay - day));
} else {
dateObj.last = year + "-" + (month - 1) + "-" + lastMonthDay;
}
} else {
dateObj.last = year + "-" + (month -1) + "-" + day + " " + hours + ":" + minutes + ":" + seconds;
}
}
return dateObj;
}