Skip to content

获取当前月份的第一天和最后一天 #32

@endday

Description

@endday
function timeFormat (date) {
    if (!date || typeof (date) === 'string') {
        throw Error('参数异常,请检查...')
    }
    var y = date.getFullYear() //年
    var m = date.getMonth() + 1 //月
    var d = date.getDate() //日
    return y + '-' + m + '-' + d
}

function getMonthFirstDay () {
    var date = new Date()
    date.setDate(1)
    return timeFormat(date)
}

function getMonthLastDay () {
    var curDate = new Date()
    var curMonth = curDate.getMonth()
    curDate.setMonth(curMonth + 1)
    curDate.setDate(0)
    return timeFormat(curDate)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions