JS 获取当前年-月-日及当月一号
// 补零函数
function doHandleZero(zero) {
var date = zero;
if (zero.toString().length == 1) {
date = "0" + zero;
}
return date;
}
// 获取每个月一号
function getDate() {
var myDate = new Date();
var tYear = myDate.getFullYear()
var tMonth = myDate.getMonth()
tMonth = doHandleZero(tMonth + 1)
return tYear + "-" + tMonth + "-01"
}
// 获取当前年-月-日
function getDateNow() {
var myDate = new Date();
var tYear = myDate.getFullYear()
var tMonth = myDate.getMonth()
var tDay = myDate.getDate()
tMonth = doHandleZero(tMonth + 1)
tDay = doHandleZero(tDay)
return tYear + "-" + tMonth + "-" + tDay
}