比较开始日期和结束日期的问题

Problem in Comparing Start date and End date

如果我使用这样的日期格式 'MM/yyyy',那么它会正常工作,但我想使用这样的日期格式 'm/YYYY'。如何比较?

下面的代码工作正常,但我想像这样使用日期格式 'm/yyyy'。

$('#card_form_plan_start_date').datepicker({
  format: 'MM/yyyy',
  autoclose: true,
  viewMode: 'months', 
  minViewMode: 'months'
});

$('#card_form_plan_start_date').datepicker().on(
      'change',
      function() {
        $('#card_form_plan_end_date').val('');
        $('#card_form_plan_end_date').removeAttr("disabled");
        $('#card_form_plan_end_date').datepicker("destroy");
        var newStart = new Date($(this).val());
alert($(this).val());        
newStart.setDate(newStart.getDate());

        $('#card_form_plan_end_date').datepicker({
            startDate : newStart,
            format: 'MM/yyyy',
              autoclose: true,
              viewMode: 'months', 
              minViewMode: 'months'
        });
});

结束月份从开始月份开始,如果我使用这样的日期格式'MM/YYYY',如何使用'm/YYYY'?

而不是var newStart = new Date($(this).val()); 尝试在您的 js

中使用以下代码
var comDate = $(this).val().split('/'); 
var newStart = new Date(comDate[1], comDate[0], 1);

$(document).ready(function() {
    $('#card_form_plan_start_date').datepicker({
  format: 'm/yyyy',
  autoclose: true,
  viewMode: 'months', 
  minViewMode: 'months'
});

$('#card_form_plan_start_date').datepicker().on(
      'change',
      function() {
        $('#card_form_plan_end_date').val('');
        $('#card_form_plan_end_date').removeAttr("disabled");
        $('#card_form_plan_end_date').datepicker("destroy");
        //var newStart = new Date($(this).val());  
        //newStart.setDate(newStart.getMonth());
        var comDate = $(this).val().split('/'); 
        var newStart = new Date(comDate[1], comDate[0], 1);
        $('#card_form_plan_end_date').datepicker({
            startDate : newStart,
            format: 'm/yyyy',
              autoclose: true,
              viewMode: 'months', 
              minViewMode: 'months'
        });
});
});
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/css/bootstrap-datepicker.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/js/bootstrap-datepicker.js"></script>

 <div class="container">
 

    <div class="row">
   
        <div class="col-sm-6">
            <div class="input-group date">
      <input type="text" id="card_form_plan_start_date" class="form-control timepicker" name="card_form_plan_start_date"> <input type="text" id="card_form_plan_end_date" class="form-control timepicker" name="card_form_plan_end_date">
                <div class="input-group-addon">
                    <span class="glyphicon glyphicon-th"></span>
                </div>
            </div>
        </div>
    </div>


</div>