-4

我需要在 javascript 中显示日期 D+3。周六和周日我没空。

前任。: 如果是 10 月 25 日星期五,则显示的日期应该是 10 月 30 日星期三。

感谢您的宝贵帮助。

4

3 回答 3

0
var today = new Date(); // Or Date.today()
var d3 = today.add(3).day();

容易对

于 2013-10-23T07:56:40.357 回答
0

这也有帮助

var today = new Date();

if(today.getDay()==0||today.getDay()==1||today.getDay()==2)
{
//sun,mon,tue
today.setDate(today.getDate() + 3); 
}
else if(today.getDay()==3||today.getDay()==4||today.getDay()==5)
{ 
//wed,thu,fri
today.setDate(today.getDate() + 5); 
} 
else
{
//sat
today.setDate(today.getDate() + 4);
}

接下来是您选择的格式

var dd = today.getDate();
var mm = today.getMonth() + 1;
var y = today.getFullYear();

var formattedDate= dd + '/'+ mm + '/'+ y;
于 2013-10-23T07:59:09.687 回答
0

我已经为一个项目制作了这个函数来计算工作日,它会为你工作。

你所要做的就是

 1. set a start date in your case current date.

 2.working days slider(no of days you want(ex: 3)) 
 and it will return end date   Excluding  Saturdays and Sundays.

function GetNextworkingDay() {
        //get the value of Start Date here
            var startDate = new Date(); // this gets the current date// can also provide any specific date here.
            var endDate = new Date();
            //Get the No of Days to perform a task.
            var NoOfDaysForTask = 3;
            //Initial End Date
            endDate.setDate(startDate.getDate() + NoOfDaysForTask);
            endDate.setHours(00, 00, 00);
            var WorkingDaysCountInRange = parseInt(GetWorkingDaysCountInRange(startDate, endDate))
            //Increase the range and calculate till we get the Specified no foworking days.
            while (NoOfDaysForTask != WorkingDaysCountInRange) {
                endDate.setDate(endDate.getDate() + parseInt(NoOfDaysForTask - WorkingDaysCountInRange));
                WorkingDaysCountInRange = parseInt(GetWorkingDaysCountInRange(startDate, endDate))
            }
            alert(endDate);
        });

    //This function will check if we are getting the required no of workingdays in the range limit passed
    //if not then range will be Increased and it will be calculated again
    function GetWorkingDaysCountInRange(startDate, endDate) {
        var taskStartDate = new Date(startDate);
        var taskCompletionDate = new Date(endDate);
        var weekDaysCount = 0
        while (taskStartDate < taskCompletionDate) {
            var day = taskStartDate.getDay();
            var isWeekend = (day == 6) || (day == 0);
            if (!isWeekend) {
                weekDaysCount++;
            }
            taskStartDate.setDate(taskStartDate.getDate() + 1);
        }
        var day = taskCompletionDate.getDay();
        var isWeekend = (day == 6) || (day == 0);
        if (isWeekend) {
            weekDaysCount--;
        }
        return weekDaysCount;
    }
于 2013-10-23T08:04:18.177 回答