如何使用Angular 5 Bootstrap Datepicker在DatePicker上设置英国格式

时间:2019-04-16 15:52:59

标签: html twitter-bootstrap datepicker

我正在尝试将uk格式设置为选定日期之后。

代码如下:

<div class="form-group">
    <label for="test_StartDate" class="col-md-12">{{l("StartDate")}}</label>
    <input *ngIf="!test.id" class="form-control m-input" type="datetime" name="test_StartDate" datePicker [(selectedDate)]="test.startDate" id="test_StartDate">
    <input *ngIf="test.id" 
           class="form-control m-input" 
           type="datetime" 
           name="test_StartDate" 
           datePicker
           [(selectedDate)]="test.startDate" 
           id="test_StartDate"
           data-date-format="DD/MM/YYYY">
</div>

输出:01/12/2019

应为:12/01/2019

1 个答案:

答案 0 :(得分:0)

要获得预期的结果,请在日期选择器配置选项中添加格式

$("#test_StartDate").datepicker({ 
        autoclose: true, 
        format: 'dd/mm/yyyy',
        todayHighlight: true
  }).datepicker('update', new Date());
#test_StartDate{
  width:150px
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.8.0/js/bootstrap-datepicker.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>

<div class="form-group">
    <label for="test_StartDate" class="col-md-12">{{l("StartDate")}}</label>
    <input *ngIf="!test.id" class="form-control m-input" type="datetime" name="test_StartDate" datePicker [(selectedDate)]="test.startDate" id="test_StartDate">
    <input *ngIf="test.id" 
           class="form-control m-input" 
           type="datetime" 
           name="test_StartDate" 
           datePicker
           [(selectedDate)]="test.startDate" 
           id="test_StartDate"
           data-date-format="DD/MM/YYYY">
</div>

codepen-https://codepen.io/nagasai/pen/ROxjrY