使用javascript获取CURRENT月份的天数 [英] get number of days in the CURRENT month using javascript
本文介绍了使用javascript获取CURRENT月份的天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于我的网站,我试图获取特定功能的当前月份的天数。
For my website I am trying to get the number of days for the CURRENT month for a certain feature.
我在网上看到的例子显示指定月份的天数,但我需要获取当前月份的日期并查找该月剩余的天数。
I have seen examples online that get days of a specified month, however I need to get the days of the CURRENT month and find how many days are left of that month.
以下是我设法汇总的代码:
Here is the code I managed to put together:
function myFunction() {
var today = new Date();
var month = today.getMonth();
console.log(month);
}
myFunction();
推荐答案
这样做你想要的吗?
function daysInThisMonth() {
var now = new Date();
return new Date(now.getFullYear(), now.getMonth()+1, 0).getDate();
}
这篇关于使用javascript获取CURRENT月份的天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文