jQuery日期和时间戳特定日期的不同时间

时间:2014-11-27 14:38:37

标签: jquery datepicker timepicker

我使用日期和时间选择器预订表格,我需要你的帮助。 http://xdsoft.net/jqplugins/datetimepicker/< - 我从

获取的源代码

我想只在星期日设定一个特定的时间段。 所以每隔一天,“允许时间”和#39;是从18:30到23:15 但在星期天12:30至22:00

这是我使用的代码

    $('#datum').datetimepicker({
    lang:'nl',
     i18n:{
      de:{
       months:[
        'Januari','Februair','Maart','April',
        'Me','Juni','Juli','Augustus',
        'September','Oktober','November','December',
       ],
       dayOfWeek:[
        "Zo.", "Ma", "Di", "Wo", 
        "Do", "Vr", "Za.",
       ]
      }
     },
    dayOfWeekStart: 1,
    minDate: 0,
    formatTime:'H:i',
    formatDate:'d.m.Y',
    minTime:'18:30',
    maxTime:'23:15',
    defaultTime:'18:30',
    onSelectTime: function(){  },
    allowTimes:['18:30','18:45','19:00','19:15','19:30','19:45','20:00','20:15','20:30','20:45','21:00','21:15','21:30','21:45','22:00','22:15','22:30','22:45','23:00','23:15'],
    beforeShowDay: function(date) {

        var day = date.getDay();
        return [(day == 0 || day >4 ), ""]; // Sunday or after Wednesday.
    }
});
提前thnx,任何帮助将不胜感激

2 个答案:

答案 0 :(得分:0)

不确定您是否找到了解决方案,但无论如何都要发布以防其他人需要帮助:

对于星期日和星期六,我们希望缩短工作时间。

var datePickerTime = function(currentDateTime) {
    // 'this' is jquery object datetimepicker
    var day = currentDateTime.getDay();
    if (day === 0 || day === 6) {
        this.setOptions({
            allowTimes: ["09:00", "10:00", "11:00", "12:00"]
        });
    } else {
        this.setOptions({
            allowTimes: ["08:00", "09:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00"]
        });
    }
};

$('#txtCallDate').datetimepicker({
    minDate: '0',        
    minDateTime: dt,
    onChangeDateTime: datePickerTime
});

答案 1 :(得分:0)

我相信您必须在构造函数中设置时间范围在回调中设置日期更改。而且我相信正确的回调是 onSelectDate 而不是 onChangeDateTime - 使用后者会在滚动时产生闪烁和时间选择小部件的重置(但是,尽管如此,感谢@WillemNicolaas 将我指向正确的方向)。下面的逻辑显示了工作日的上午 9 点到晚上 7 点,周末的时间是上午 11 点到晚上 7 点,这正是我想要的。

d = new Date(); 
weekendTimes = [
        '11:00', '11:30', '12:00', '12:30', '13:00', '13:30', '14:00', '14:30', '15:00', '15:30', '16:00', '16:30', '17:00', '17:30', '18:00', '18:30', '19:00'
           ]; 
weekdayTimes = [
        '9:00', '9:30', '10:00', '10:30', '11:00', '11:30', '12:00', '12:30', '13:00', '13:30', '14:00', '14:30', '15:00', '15:30', '16:00', '16:30', '17:00', '17:30', '18:00', '18:30', '19:00'
           ]; 


if ((d.getDay() == 6) || (d.getDay() == 0)) { 
   times = weekendTimes; 
} else {
   times = weekdayTimes; 
}
var datePickerTime = function(currentDateTime) {
   // 'this' is jquery object datetimepicker
   var day = currentDateTime.getDay();
   if (day === 0 || day === 6) {
       this.setOptions({
           allowTimes: weekendTimes 
       });
   } else {
       this.setOptions({
           allowTimes: weekdayTimes 
       });
   }
};
jQuery('input[name="order_delivery_date"]').datetimepicker({
    inline:true,
    minDate:0,
    onSelectDate: datePickerTime,
    defaultDate: d, 
    allowTimes: times, 
    formatTime:'g:i A'
});