0

当我从 AM/PM 更改为 24 时钟时,小时选择器只允许提前 23 小时。这是日期范围选择器或 moment.js 转换问题的常见错误吗?

如果 moment.js 从我的服务器占用时间,我会上传我的照片吗?而且不能超过23小时...

在此处输入图像描述

另请参阅 codepen 和我的代码。

"setStartDate": [moment().startOf('day')],
"setEndDate": [moment()]

https://codepen.io/anon/pen/WMOmOO

4

1 回答 1

1

请注意该format选项,您必须使用有效的时刻标记,MM代表月份,小写mm代表分钟,SS代表小数秒,使用小写表示秒ss,请参阅时刻文档以获取更多参考。

此外startDateendDate 选项接受日期对象、时刻对象或字符串,您正在传递一个数组,这就是您得到无效日期的原因。

这是一个现场片段:

$('#demo').daterangepicker({
    "timePicker": true,
    "timePicker24Hour": true,
    "autoApply": true,
    "locale": {
        "format": "DD/MM/YYYY HH:mm:ss",
        "separator": " - ",
        "applyLabel": "Apply",
        "cancelLabel": "Cancel",
        "fromLabel": "From",
        "toLabel": "To",
        "customRangeLabel": "Custom",
        "weekLabel": "W",
        "daysOfWeek": [
            "Su",
            "Mo",
            "Tu",
            "We",
            "Th",
            "Fr",
            "Sa"
        ],
        "monthNames": [
            "January",
            "February",
            "March",
            "April",
            "May",
            "June",
            "July",
            "August",
            "September",
            "October",
            "November",
            "December"
        ],
        "firstDay": 1
    },
    "startDate": moment().startOf('day'),
    "endDate": moment()
}, function(start, end, label) {
  console.log("New date range selected: ' + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD') + ' (predefined range: ' + label + ')");
});
<script type="text/javascript" src="https://cdn.jsdelivr.net/jquery/1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/bootstrap/3/css/bootstrap.css" />
 
<!-- Include Date Range Picker -->
<script type="text/javascript" src="https://cdn.jsdelivr.net/bootstrap.daterangepicker/2/daterangepicker.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/bootstrap.daterangepicker/2/daterangepicker.css" />

<input type="text" id="demo" style="width: 300px;"></input>

于 2018-02-13T11:06:10.340 回答