简体   繁体   中英

Bootstrap 4 datetimepicker - How can I display date format differently between value for sending?

I have a datetimepicker() ID's start_date that same an input name. In props, format YYYY-MM-DD. I want to use this format for my API but in an input DOM, my user going to looking like DD-MM-YYYY.

$('#start_date').datetimepicker({
  format: 'YYYY-MM-DD'
});

This code has I used but my expectation as display the date & month & year (DD-MM-YYYY) and actually the value that is the year & month & date (YYYY-MM-DD). When I get $('#start_date').val() should be return YYYY-MM-DD.

EDIT: the example code is now I used. so this's what I want.

    <div class="input-group date" id="start_date">
      <div class="input-group-prepend">
        <span class="input-group-text">
            <i class="far fa-calendar-alt"></i>
        </span>
      </div>
     <input type="text" name="start_date" class="form-control"/>
    </div>

## jquery
  $('#start_date').datetimepicker({
  // display --> DD-MM-YYYY
  // value --> YYYY-MM-DD
});
$('#start_date').val().format("YYYY-MM-DD")

即使对象已使用不同的格式初始化,也将返回您正在寻找的内容。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM