首页 > 解决方案 > My jquery code for showdays was working with accurate date now but now it is 1 day less

问题描述

below is my code. It was working fine but now the days til task is off by 1? Also if anyone can help me put like a count on my div where it shows the number of inputed tasks each time the add button gets click and sort the tasks by the dates automatically

jQuery(
  function() {

    $("#tbDate").datepicker({
      dateFormat: "MM dd, yy",
      onSelect: function() {
        showDays();
      }
    });

    $("#addBtn").click(
      function() {
        var tskTxt = $("#addTb").val();

        $("#ulData").append("<li style = 'font-family: arial;'><strong>" + tskTxt + "</strong></li>");

        var dateTxt = $("#tbDate").val();

        $("#ulData").append("<li style = 'font-family: arial;'><strong>" + dateTxt + "</strong></li>");

        $("#ulData").append("<li style='font-size: 14px;'>" + "# of Days until deadline: " + diff + " days" + "</li>");

        $(".clear").val("");
      });

    function showDays() {
      var now = new Date();
      var end = $("#tbDate").datepicker("getDate");
      diff = Math.round((end.getTime() - now.getTime()) / (86400000));
    }
  });

标签: jquerydate-difference

解决方案


推荐阅读