本文介绍了Momentjs下一个工作日的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用我的代码获得下一个工作日,但是它无法正常工作.仅在第二天显示.我尝试检查其他问题以查找错误,但仍然无法解决.

I'm trying to get the next business day with my code, but it's not working correctly. It's just showing the next day. I've tried to check other questions to find the error, but I still can't figure it out.

这个问题适用于我自己的问题,但不完全适用:

This question applies to my own but not exactly:

如何使用Moment排除两个日期之间的周末.js

 $scope.businessDay = new Date();

        if (moment().day() === 5) { // friday, show monday
            // set to monday
            $scope.businessDay=moment().weekday(8).format("MMMM Do YYYY");
        }
        if (moment().day() === 6) { // saturday, show monday
            // set to monday
            $scope.businessDay=moment().weekday(8).format("MMMM Do YYYY");
        }
        else { // other days, show next day
            $scope.businessDay= moment().add('days', 1).format("MMMM Do YYYY");
        }

推荐答案

工作正常.您刚刚错过了else

It's working fine. You've just missed an else

    if (moment().day() === 5) { // friday, show monday
        // set to monday
        $scope.businessDay=moment().weekday(8).format("MMMM Do YYYY");
--> } else if (moment().day() === 6) { // saturday, show monday
        // set to monday
        $scope.businessDay=moment().weekday(8).format("MMMM Do YYYY");
    }
    else { // other days, show next day
        $scope.businessDay= moment().add('days', 1).format("MMMM Do YYYY");
    }

这篇关于Momentjs下一个工作日的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 15:30
查看更多