如何在daterangepicker中添加时间

时间:2017-04-05 11:50:47

标签: javascript jquery twitter-bootstrap bootstrap-daterangepicker

我需要使用jQuery和JavaScript在daterangepicker中添加时间。我在下面解释我的代码。

<input class="form-control" name="startgroupdate" id="stdate" type="text" placeholder=""  onfocus="removeBorder('stdate')">
$('input[name="startgroupdate"]').daterangepicker({
    singleDatePicker: true,
    showDropdowns: true,
    drops: "up",
    minDate: '01/01/2012',
    maxDate: '12/31/2017'
});

这里只有日期来自日历,但我还要加上时间,所以结果应该像“03/04/2017 12 10 PM”。

3 个答案:

答案 0 :(得分:3)

检查出来..你需要添加时间属性和daterangepicker js

<!DOCTYPE html>
<html>

<head>
  <script data-require="jquery@*" data-semver="3.1.1" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  <link data-require="bootstrap@*" data-semver="4.0.5" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" />
  <script type="text/javascript" src="https://netdna.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>

  <link rel="stylesheet" href="style.css" />
  <link href="daterangepicker-bs3.css" rel="stylesheet" type="text/css" />
  <script src="moment.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-daterangepicker/2.1.25/daterangepicker.js"></script>
  <script src="script.js"></script>

</head>

<body>
  <h1>Hello Plunker!</h1>
  <input class="form-control" name="startgroupdate" id="stdate" type="text" placeholder="">
  <script>
    $(function() {
      $('input[name="startgroupdate"]').daterangepicker({
        timePicker: true,
        locale: {
          format: 'MM/DD/YYYY h:mm A'
        },
        singleDatePicker: true,
        showDropdowns: true,
        drops: "down",
        minDate: '01/01/2012',
        maxDate: '12/31/2017'
      });
    });
  </script>
</body>

</html>

答案 1 :(得分:2)

您需要将timepicker标志添加到daterangepicker。

$('input[name="startgroupdate"]').daterangepicker({
    timePicker: true,
    timePickerIncrement: 30,
    singleDatePicker: true,
    showDropdowns: true  
    drops: "up",
    minDate: '01/01/2012',
    maxDate: '12/31/2017'
});

答案 2 :(得分:1)

哟必须添加属性

 timePicker: true

可能这个链接有帮助 http://www.daterangepicker.com/#ex2