使用DateTimePicker获取日期名称并更改服务小时列表

时间:2017-07-18 10:51:16

标签: javascript php jquery html bootstrap-datetimepicker

我使用位于here

的DateTimePicker脚本为咨询协议列表创建了一个应用程序

直到现在一切正常,现在,我想要的是如何检索当天名称的数据,然后更改咨询服务时钟(radiobutton)列表。

例如: 周一至周四有3种选择:

  1. 08 - 10
  2. 10 - 12
  3. 13 - 15
  4. 周五:

    1. 09 - 10
    2. 10-11.30
    3. 13.30 - 15
    4. 遵循现有脚本

      <div id="datedays">
          <div class="controls input-append date form_date" data-date="" data-date-format="dd-mm-yyyy" data-link-field="dtp_input1" data-link-format="yyyy-mm-dd">
              <input class="date" size="16" type="text" value="" readonly>
              <span class="add-on"><i class="icon-remove"></i></span>
              <span class="add-on"><i class="icon-th"></i></span>
          </div>
          <input name="tanggal" type="hidden" id="dtp_input1" value="" />
          <input name="harinya" type="hidden" id="daynames" value="" />
      </div>
      <div id="hourpick">
          <input type="radio" name="hours" value="1"> 09.00 - 10.00<br/>
          <input type="radio" name="hours" value="2"> 10.00 - 12.00<br/>
          <input type="radio" name="hours" value="3"> 13.00 - 15.00<br/>
      </div>
      <script type="text/javascript">
          $('.form_date').datetimepicker({
              language:  'id',
              startDate:'<?php echo date('Y-m-d', strtotime($date .' +2 day'));?>',
              weekStart: 1,
              daysOfWeekDisabled:[0,6],
              todayBtn:  0,
              autoclose: 1,
              todayHighlight: 1,
              startView: 2,
              minView: 2,
              forceParse: 0
          });
      </script>
      

      更新

      我发现在bootstrap-datetimepicker.en.js(包含在DateTimePicker下载包中)这段代码

      ;(function($){
          $.fn.datetimepicker.dates['id'] = {
              days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
              daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
              daysMin: ["Sn", "Mn", "Tu", "Wd", "Th", "Fr", "Sa", "Sn"],
              months: ["January", "February", "March", "April", "May", "Juni", "July", "Augusts", "September", "October", "November", "December"],
              monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
              today: "Today",
              suffix: [],
              meridiem: [],
              weekStart: 1,
              format: "dd/mm/yyyy hh:ii:ss"
          };
      }(jQuery));
      

      但我仍然不知道如何获得那天的价值

1 个答案:

答案 0 :(得分:0)

您可以使用日期格式来获取星期几

更多信息here。寻找“w”

$dayOfTheWeek = intval(date("w"));

if($dayOfTheWeek >= 1 && $dayOfTheWeek <= 4) {
    //Monday to Thursday
} elseif($dayOfTheWeek <= 5) {
    //Friday
} else {
    //other days
}