Javascript 如何在fullcalendar控件中获取每月和每周的第一个星期一

Javascript 如何在fullcalendar控件中获取每月和每周的第一个星期一,javascript,jquery,asp.net-mvc-5,fullcalendar,Javascript,Jquery,Asp.net Mvc 5,Fullcalendar,我有一个与fullCalendar control相关的案例。我显示从周一至周五的天数,并添加了名为“添加新约会”的自定义按钮。当用户单击此按钮时,我们需要显示月视图的第一个星期一日期,如果是周视图,我们需要显示该周的第一个日期(星期一)。” 我已经这样做了,直到现在它的IST时区工作,但我的客户是CST/EST,这需要前一天。示例-月视图如果我转到2月并单击“添加新”,则应为2016年2月2日,但时间为2015年1月31日 function processDateTimeForNewCalen

我有一个与fullCalendar control相关的案例。我显示从周一至周五的天数,并添加了名为“添加新约会”的自定义按钮。当用户单击此按钮时,我们需要显示月视图的第一个星期一日期,如果是周视图,我们需要显示该周的第一个日期(星期一)。”

我已经这样做了,直到现在它的IST时区工作,但我的客户是CST/EST,这需要前一天。示例-月视图如果我转到2月并单击“添加新”,则应为2016年2月2日,但时间为2015年1月31日

function processDateTimeForNewCalendar() {
    debugger;
    var mondayForWeek = common.getMondayForCurrentWeek(new Date());

    var dateHeader = $('div.fc-center h2').text();
    var view = $('#calendar').fullCalendar('getView');
    var date, sTime, eTime;
    var currentDate = new Date();
    if (view.name === 'month') {
        debugger;
        var currentMonth = dateHeader.split(" ")[0];
        var currentYear = dateHeader.split(" ")[1];
        var monthInNo = common.getMonthNumberByMonthName(currentMonth);

        var temp = currentDate.getDate() + "-" + currentMonth + "-" + currentYear + " " + currentDate.getHours() + ":" + currentDate.getMinutes()
        var tempDate = new Date(temp);
        var mondayForWeek = common.getMondayForCurrentWeek(tempDate);

        if ((currentDate.getMonth() + 1) === monthInNo)
            date = new Date(currentDate.getDate() + "-" + currentMonth + "-" + currentYear + " " + currentDate.getHours() + ":" + currentDate.getMinutes());
        if ((currentDate.getMonth() + 1) < monthInNo || (currentDate.getMonth() + 1) > monthInNo)
            date = new Date(view.intervalStart);


        sTime = moment(date).format("hh:mm A");
        eTime = moment(date).add(30, 'minutes').format("hh:mm A");
    }
    if (view.name === 'agendaWeek' || view.name === 'agendaDay') {
        date = new Date(view.start);
        date = moment(date).format("MM/DD/YYYY");
        sTime = moment(currentDate).format("hh:mm A");
        eTime = moment(currentDate).add(30, 'minutes').format("hh:mm A");
    }
    $(CALENDAR.ApptStartDateById).val(moment(date).format("MM/DD/YYYY"));
    $(CALENDAR.ApptEndDateById).val(moment(date).format("MM/DD/YYYY"));
    $(CALENDAR.ApptStartTime).timepicker("setTime", sTime);
    $(CALENDAR.ApptEndTime).timepicker("setTime", eTime);

    $(CALENDAR.Duration).val(calculateDuration());
    $(CALENDAR.ApptStartDateById).datepicker("update", date).datepicker('fill');
    $(CALENDAR.ApptEndDateById).datepicker("update", date).datepicker('fill');
}
函数processDateTimeForNewCalendar(){
调试器;
var mondayForWeek=common.getMondayForCurrentWeek(新日期());
var dateHeader=$('div.fc-center h2').text();
变量视图=$(“#日历”).fullCalendar('getView');
变量日期、时间、时间;
var currentDate=新日期();
如果(view.name=='month'){
调试器;
var currentmount=dateHeader.split(“”[0];
var currentYear=dateHeader.split(“”[1];
var monthInNo=common.getMonthNumberByMonthName(当前月);
var temp=currentDate.getDate()+“-”+currentMonth+“-”+currentYear+“+currentDate.getHours()+”:“+currentDate.getMinutes()
var tempDate=新日期(temp);
var mondayForWeek=common.getMondayForCurrentWeek(tempDate);
如果((currentDate.getMonth()+1)==monthInNo)
日期=新日期(currentDate.getDate()+“-”+currentMonth+“-”+currentYear+“+currentDate.getHours()+”:“+currentDate.getMinutes());
如果((currentDate.getMonth()+1)monthInNo)
日期=新日期(view.intervalStart);
时间=时刻(日期)。格式(“hh:mm A”);
时间=时刻(日期)。添加(30,'分钟')。格式(“hh:mm A”);
}
如果(view.name=='agendaWeek'| | view.name==='agendaDay'){
日期=新日期(view.start);
日期=时刻(日期)。格式(“MM/DD/YYYY”);
时间=力矩(当前日期)。格式(“hh:mm A”);
时间=时刻(当前日期)。添加(30,'分钟')。格式(“hh:mm A”);
}
$(CALENDAR.ApptStartDateById).val(矩(日期).format(“MM/DD/YYYY”);
$(CALENDAR.ApptEndDateById).val(矩(日期).format(“MM/DD/YYYY”);
$(CALENDAR.ApptStartTime).timepicker(“setTime”,sTime);
$(CALENDAR.ApptEndTime).timepicker(“setTime”,eTime);
$(CALENDAR.Duration).val(calculateDuration());
$(CALENDAR.ApptStartDateById).datepicker(“更新”,date.datepicker('fill');
$(CALENDAR.ApptEndDateById).datepicker(“更新”,日期).datepicker(“填充”);
}
请帮我修一下

谢谢,
Amod

您可以使用
$('calendar selector').fullCalendar('getView').start
获取当前视图的开始日期

我用另一种方式,找到了一个月的第一天,然后检查它是否是星期天。如果是,则添加+1天。检查下面的代码-

function getFirstDayOfMonth(d) {                
        d.setMonth(d.getMonth(), 1);        
        // if sunday add +1 day
        if (d.getDay() === 0)
            d.setDate(d.getDate() + 1, 1);
        return d;
    }

希望,这是使用fullCalendar查找每月第一天的另一种解决方案。

请提供您到目前为止尝试过的方法。@ChrisBeckett-谢谢,当然可以。请再核对一下这个问题。我已经把代码和问题放在一起了。我的另一个担忧是,我不允许fullcalendar使用UTC,因此在选项中设置了时区:'local'。我可以为$(“#Calendar”).fullCalendar('getView')关闭时区吗;我已经用它检查代码了。但我认为,当我的客户在他的环境中进行测试时,它的开始时间是1天,即2月1日,它应该是第一个星期一,即2016年2月1日,但它的开始时间是2015年12月31日。如果您将其更改为$('calendar selector')。fullCalendar('getView')。start.startOf('month')?我也进行了检查,但仍然显示了以前的日期。我想得到一个月的第一个星期一和一周的第一个星期一,然后操纵日期。