如何根据所选时区更改日期和时间?

时间:2019-02-06 04:17:50

标签: javascript php twig bootstrap-datetimepicker timezone-offset

dispalys the timezone in dropdown ....... bootstrap datetimepicker我有一个下拉菜单,其中显示了所有时区。我有一个引导datetimepicker。第一个下拉菜单中的时区onselectdatetimepicker中的日期和时间需要根据所选时区进行更改。

datetimepicker的代码

<div class="form-group">

  <div class='input-group date' id='datetimepicker5'>
    <input type='text' class="form-control"   placeholder="start-date" required />
    <span class="input-group-addon">
      <span class="glyphicon glyphicon-calendar"></span>
    </span>
  </div>

  <script type="text/javascript">
    $(function () {
      $('#datetimepicker5').datetimepicker({
        defaultDate: moment(),
        widgetPositioning:{
          horizontal: 'auto',
          vertical: 'top'
        }
      });
    });
  </script>

</div>

这是用于显示时区的代码

<div class="form-group">
  <select class="form-control"  id="shiftroster_timezone"  required>
    <option value=" "> select timezone</option>
    {% for table in zoned_array %}
    {% set selected = '' %}
    {% if (table.zone ~ ' ' ~ table.diff_from_GMT) == services_names %}
    {% set selected = 'selected' %}
    {% endif %}
    <option value="{{table.diff_from_GMT}}" {{ selected }}>  {{table.zone}} {{table.diff_from_GMT}}</option>
    var_dump{{table.diff_from_GMT}};
    {% endfor %}
  </select>
</div>

用于显示时区的PHP代码

$zones_array = array();
$timestamp = time();
foreach(timezone_identifiers_list() as $key => $zone) {
  date_default_timezone_set($zone);
  $zones_array[$key]['zone'] = $zone;
  $zones_array[$key]['diff_from_GMT'] = 'UTC/GMT ' . date('P', $timestamp);
}

0 个答案:

没有答案