首页 > 解决方案 > 我想在输入字段中将日期格式更改为 yyyy-mm-dd

问题描述

<input type="text" name="daterange" class="form-control input-box-style "  PLACEHOLDER="calendar"  id="dateone"   />    

<script type="text/javascript">
 $(document).ready(function() {

        updateConfig();

        function updateConfig() {
          var options = {};
          options.opens = "center";

options.ranges = {
       format: 'YYYY-MM-DD',
              'Today': [moment(), moment()],
              'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
              'Last 7 Days': [moment().subtract(6, 'days'), moment()],
              'Last 30 Days': [moment().subtract(29, 'days'), moment()],
              'This Month': [moment().startOf('month'), moment().endOf('month')],
              'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
            };
        $('#dateone').daterangepicker(options, function(start, end, label) { 
          var startDate = start.format('YYYY-MM-DD'); var endDate = end.format('YYYY-MM-DD');
          passDate(startDate,endDate);    
           });

        }

      });



function passDate(startDate,endDate) {
//alert(endDate);
$.ajax({
         type: "POST",
         url: "user_event_datepick.php",
          //data: 'startDate='+startDate,

     data: {
                      startDate: startDate,
                      endDate:endDate   
                     },
         success: function(response){
      // alert(response);
         $('#cat').html(response);
         }
         });
}

</script>

当我将日期传递到搜索页面时,日期值显示为 mm/dd/yyyy....您能帮我颠倒顺序并将 / 移至 -

标签: javascriptphp

解决方案


推荐阅读