Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
endday opened this issue Mar 21, 2019 · 0 comments
Open

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

endday opened this issue Mar 21, 2019 · 0 comments

Comments

@endday
Copy link
Owner

endday commented Mar 21, 2019

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)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant