2013-09-26 44 views
8

Tôi đang sử dụng jQuery datepicker với minDate là 4 trừ ngày cuối tuần và ngày lễ và điều chỉnh minDate để loại trừ ngày hiện tại sau 2 giờ chiều. Bây giờ tôi cần phải bằng cách nào đó yếu tố trong múi giờ bởi vì tôi muốn điều này được dựa trên múi giờ của tôi, PT, không phải múi giờ của người dùng. Tôi biết tôi getTimeZoneOffset có thể là một lựa chọn khả thi nhưng tôi đang đấu tranh với cách & nơi để thêm này vào thiết lập hiện tại của tôi.Kế toán múi giờ với jQuery datepicker

<script type="text/javascript"> 
$(document).ready(function() { 

    //holidays 
    var natDays = [ 
     [1, 1, 'New Year'], //2014 
     [1, 20, 'Martin Luther King'], //2014 
     [2, 17, 'Washingtons Birthday'], //2014  
     [5, 26, 'Memorial Day'], //2014 
     [7, 4, 'Independence Day'], //2014 
     [9, 1, 'Labour Day'], //2014 
     [10, 14, 'Columbus Day'], //2013 
     [11, 11, 'Veterans Day'], //2013 
     [11, 28, 'Thanks Giving Day'], //2013 
     [12, 25, 'Christmas'] //2013  
]; 

    var dateMin = new Date(); 
    dateMin.setDate(dateMin.getDate() + (dateMin.getHours() >= 14 ? 1 : 0)); 
    AddBusinessDays(dateMin, 4); 

    function AddBusinessDays(curdate, weekDaysToAdd) { 
     while (weekDaysToAdd > 0) { 
      curdate.setDate(curdate.getDate() + 1); 
      //check if current day is business day 
      if (noWeekendsOrHolidays(curdate)[0]) { 
       weekDaysToAdd--; 
      } 
     } 
    }  

    function noWeekendsOrHolidays(date) { 
     var noWeekend = $.datepicker.noWeekends(date); 
     if (noWeekend[0]) { 
      return nationalDays(date); 
     } else { 
      return noWeekend; 
     } 
    } 
    function nationalDays(date) { 
     for (i = 0; i < natDays.length; i++) { 
      if (date.getMonth() == natDays[i][0] - 1 && date.getDate() == natDays[i][1]) { 
       return [false, natDays[i][2] + '_day']; 
      } 
     } 
     return [true, '']; 
    } 
     $('#datepicker').datepicker({ 
      inline: true, 
      beforeShowDay: noWeekendsOrHolidays,   
      showOn: "both",    
      firstDay: 0, 
      dateformat: "dd/mm/yy", 
      changeFirstDay: false, 
      showButtonPanel: true,  
      minDate: dateMin    
    }); 
    }); 
    </script> 

<p> 
<label for="datepicker">Desired Delivery Date: </label> 
    <input class="input-medium" type="text" id="datepicker" placeholder="ex. 01/01/2013" name="properties[Delivery Date]" readonly /> 
    <label><font size=1>Need it faster? Please call us! (800) 880-0307</font> 
    </label></p> 
<style> 
    #datepicker { height: 20px; } 
    #datepicker {-webkit-border-radius: 0 3px 3px 0; -moz-border-radius: 0 3px 3px 0; border-radius: 0 3px 3px 0;} 
</style> 

Trả lời

8

Hãy thử điều này:

var localTime = new Date(); 
var ptTime = new Date(); 
ptTime.setMinutes(ptTime.getMinutes() + localTime.getTimezoneOffset() - 420); 
alert(localTime + ' ' + localTime.getTimezoneOffset() + ' ' + ptTime); 
+0

Cảm ơn bạn rất nhiều! Điều này thật đúng với gì mà tôi đã tìm kiếm! – susan

Các vấn đề liên quan