JavaScript求当月天数

上面是我写的,刚才在网上看到一段更精悍的写法:

// 求当月天数
function maxDay(){
var d = new Date();
return new Date(d.getFullYear(), d.getMonth() + 1, 0).getDate();
}

原理:下个月的0号就是当月的最后一天。

相关文章:

  • 2022-01-21
  • 2022-12-23
  • 2021-10-22
  • 2021-12-08
  • 2021-08-04
  • 2021-08-10
  • 2021-09-04
  • 2021-07-20
猜你喜欢
  • 2022-12-23
  • 2021-08-28
  • 2021-07-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-25
相关资源
相似解决方案