JS怎么获取系统时间上一个月份的天数

JavaScript011

JS怎么获取系统时间上一个月份的天数,第1张

var getLastDays = function(){

    var now = new Date

    now.setMonth(now.getMonth() - 1)

    now.setDate(1)

    var next = new Date

    next.setDate(1)

    var arr = []

    while(now < next){

        arr.push(now.getDate())

        now.setDate(now.getDate() + 1)

    }

    return arr

}

console.log(getLastDays())

<script>

document.writeln('练习6:<br>'+' 输入年份、月份,显示当月的天数'+'<br>')

var year= parseInt(prompt('练习6\n请输入一个年份'))

var month= parseInt(prompt('练习6\n请输入一个月份'))

document.writeln('您输入了'+year+'年'+'<br>')

document.writeln('您输入了'+month+'月'+'<br>')

switch(month)

{

case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

case 12:

document.writeln('您输入的'+month+'月'+'有31天')

break

case 4:

case 6:

case 9:

case 11:

document.writeln('您输入的'+month+'月'+'有30天')

break

case 2:

if(year%4===0&&year%100!==0||year%400===0)

{

document.writeln('您输入的'+month+'月'+'有29天')

}else

{

document.writeln('您输入的'+month+'月'+'有28天')

}

// (years%4===0&&years%100!==0||years%400===0)?

// document.writeln('本月有29天'):

// document.writeln('本月有28天')

break

ddefault :

document.writeln('亲,您的输入不正确'+'您输入的是'+month+'月')

break

}

</script>