Date.prototype.format = function(format) {
    var o = {
        "M+": this.getMonth() + 1, //month
        "d+": this.getDate(), //day
        "h+": this.getHours(), //hour
        "m+": this.getMinutes(), //minute
        "s+": this.getSeconds(), //second
        "q+": Math.floor((this.getMonth() + 3) / 3), //quarter
        "S": this.getMilliseconds() //millisecond
    }
    if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
        (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(format))
            format = format.replace(RegExp.$1,
                RegExp.$1.length == 1 ? o[k] :
                    ("00" + o[k]).substr(("" + o[k]).length));
    return format;
}

const formatDateyyyyMMdd = function(date) {
    return date.format("yyyy-MM-dd");
}

const yyyyMMddHHmmss = function (date) {
    return date.format("yyyy-MM-dd hh:mm:ss");
}

const getFirstDayOfThisYear = function() {
    var nowdays = new Date();
    var year = nowdays.getFullYear();
    return new Date(year, 0, 1);
}

const getFirstDayOfLastYear = function() {
    var nowdays = new Date();
    var year = nowdays.getFullYear();
    return new Date(year - 1, 0, 1);
}

const getFirstDayOfLastXMonth = function(x) {
    var nowdays = new Date();
    var year = nowdays.getFullYear();
    var month = nowdays.getMonth();
    if (month < x) {
        month = month + 12 - x;
        year = year - 1;
    } else {
        month = month - x;
    }
    return new Date(year, month, 1);
}
const getCurrDate=function(){
    //获取当前时间并打印
    let yy = new Date().getFullYear();
    let mm = new Date().getMonth()+1;
    let dd = new Date().getDate();
    let hh = new Date().getHours();
    let mf = new Date().getMinutes()<10 ? '0'+new Date().getMinutes() : new Date().getMinutes();
    let ss = new Date().getSeconds()<10 ? '0'+new Date().getSeconds() : new Date().getSeconds();
    return   yy+'-'+mm+'-'+dd+' '+hh+':'+mf+':'+ss;
}
const getLastDayOfLastXMonth = function(x) {
    var tDate = getFirstDayOfLastXMonth(x - 1);
    tDate.setDate(tDate.getDate(-1));
    return tDate;
}

export default {
    getCurrDate,
    yyyyMMddHHmmss,
    formatDateyyyyMMdd,
    getFirstDayOfThisYear,
    getFirstDayOfLastYear,
    getFirstDayOfLastXMonth,
    getLastDayOfLastXMonth
}
