使用moment.js获取当月的天数 [英] Using moment.js to get number of days in current month
本文介绍了使用moment.js获取当月的天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用moment.js获取当月的天数?最好没有临时变量。
How would one use moment.js to get the number of days in the current month? Preferably without temporary variables.
推荐答案
时刻有一个 daysInMonth
功能:
Moment has a daysInMonth
function:
每月天数 1.5.0 +
moment().daysInMonth();
获取当月的天数。
moment("2012-02", "YYYY-MM").daysInMonth() // 29
moment("2012-01", "YYYY-MM").daysInMonth() // 31
这篇关于使用moment.js获取当月的天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文