【发布时间】:2022-01-19 05:35:36
【问题描述】:
我需要一个 JS 函数来获取该月的最后一个日期。 例如,我需要得到本月的最后一个星期三。
我将传递年、月和日作为参数。
getLastDayOfMonth('2022', '02', 'Wednesday');
function getLastDayOfMonth(year, month, day){
// Output should be like this
2022-02-23
(this is last Wednesday of the month, according to the arguments- Year, month and Day)
}
【问题讨论】:
-
必须是日期名称字符串吗?数字 (0-6) 更容易匹配 Date.prototype.getDay()
-
@knicholas 停止推荐 Moment.js。即使他们现在也不推荐自己
-
@knicholas Brother 你知道这个功能吗?在 date-fns 库中。目前,我正在使用 date-fns 库。但我找不到这样做的方法。
-
@Niranga 是stackoverflow.com/questions/222309/calculate-last-day-of-month 的重复问题吗?
标签: javascript node.js date