添加否。在约会的日期(周末除外) [英] Add no. of days in a date to get next date(excluding weekends)

查看:113
本文介绍了添加否。在约会的日期(周末除外)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有约会,我需要加上否。获取未来日期的天数,但应排除周末。

I have an date, i need to add no. of days to get future date but weekends should be excluded. i.e

input date = "9-DEC-2011";
No. of days to add  = '13';

next date should be "28-Dec-2011"

这里周末(sat / sun)不计算在内。

Here weekends(sat/sun) are not counted.

推荐答案

试试这个

var startDate = "9-DEC-2011";
startDate = new Date(startDate.replace(/-/g, "/"));
var endDate = "", noOfDaysToAdd = 13, count = 0;
while(count < noOfDaysToAdd){
    endDate = new Date(startDate.setDate(startDate.getDate() + 1));
    if(endDate.getDay() != 0 && endDate.getDay() != 6){
       //Date.getDay() gives weekday starting from 0(Sunday) to 6(Saturday)
       count++;
    }
}
alert(endDate);//You can format this date as per your requirement

工作 演示

Working Demo

这篇关于添加否。在约会的日期(周末除外)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆