日期选择器时间不相等怎么修

datepicker time is not equal how to fix

提问人:Narish 提问时间:7/12/2023 最后编辑:Narish 更新时间:7/12/2023 访问量:34

问:

todayDateTime显示正确的时间,但显示不正确的时间。它增加了 7 小时。我希望它显示正确的时间,而无需我减去小时数。startDateTest

function setDatePicker() {
  $('.datepicker').datepicker();

  success: function(data) {
    var todayDateTime = eval(data.date.replace(/\/Date\((\d+)\)\//gi, "new Date($1)"));
    var todayDate = eval(data.date.replace(/\/Date\((\d+)\)\//gi, "new Date($1)"));
    todayDate.setHours(0, 0, 0, 0);

    var newDateObj = new Date();
    var n = todayDateTime.getHours();
    if (n < 7) {
      todayDateTime.setHours(7, 0, 0, 0);
    }
    newDateObj.setTime(todayDateTime.getTime() + (30 * 60 * 1000));

    $('#dpVBH_START_DATE').datepicker({
      autoclose: true
    });
    $("#dpVBH_START_DATE").datepicker("setDate", todayDateTime);
    $("#dpVBH_START_TIME").data("kendoTimePicker").value(todayDateTime);
    $('#dpVBH_FINISH_DATE').datepicker({
      autoclose: true
    });
    $("#dpVBH_FINISH_DATE").datepicker("setDate", newDateObj);
    $("#dpVBH_FINISH_TIME").data("kendoTimePicker").value(newDateObj);

    var startdatetest = $("#dpvbh_start_date").data('datepicker').date;
    console.log("startDateTest", startDateTest);
    console.log("todayDateTime", todayDateTime);
    console.log("todayDate", todayDate);
  }
}

enter image description here

javascript jquery datetime 时间 datepicker

评论

0赞 mplungjan 7/12/2023
请发布一个最小的可重现示例,注明输入和预期输出,最好是在 Stacksnippet
1赞 mplungjan 7/12/2023
function setDatePicker() { $('.datepicker').datepicker(); success: function(data) {无效的 JS,请创建一个运行示例
0赞 Dai 7/12/2023
出于好奇,您是否有充分的理由将 jQuery(现在已经过时了,现在是 2023 年......来吧)与基于 jQuery 的日期选择器一起使用,而不仅仅是使用 HTML 的?<input type="datetime-local">

答: 暂无答案