gpt4 book ai didi

javascript - 片刻如何获得上个月(十二月)的最后一个工作日

转载 作者:行者123 更新时间:2023-11-30 07:55:19 25 4
gpt4 key购买 nike

我正在遵循本指南 Get the First Weekday of the Month with moment.js

获取第一个月(一月)的第一个工作日效果很好

但是,当我尝试使用相反的方法时。我得到了 12 月的最后一个工作日。我尝试更改 add in minus 和 sub 但不起作用

最佳答案

您可以使用 moment-business-days进行工作日相关处理。如果你做更多这样的处理而不仅仅是这个问题,事情会容易得多。

var moment = require('moment-business-days');

// Set the date for december. You can use this for any month.
// Get array of business days for the month
var businessDays=moment('01-12-2017', 'DD-MM-YYYY').monthBusinessDays();

// Get last business day from the array
var lastBusinessDay = businessDays[businessDays.length-1]._d;

console.log(lastBusinessDay);

可以看到输出here或克隆并编辑它。这是 fiddle

关于javascript - 片刻如何获得上个月(十二月)的最后一个工作日,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41541999/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com