我希望以下一格式显示日期:dd/MM/yyyy
,但它只显示在MM/dd/yyyy
中。
这是我的startdateComponent
:
import {Component, EventEmitter, Output, Input} from '@angular/core';
import {DATEPICKER_DIRECTIVES} from 'ng2-bootstrap/components/datepicker';
@Component({
templateUrl:'./app/home/item_component/start_date_component/start_date_component.html',
directives: [DATEPICKER_DIRECTIVES]
})
export class StartDateComponent () {
chosenDate : Date = new Date();
getDate() {
return this.chosenDate;
}
}
模板是:
<div class="col-sm-1 col-sm-offset-1 datePicked ">
<span>
<h4>{{getDate() | date: 'dd/MM/yyyy'}}</h4>
</span>
</div>
这里有什么问题?
答案 0 :(得分:0)
我有同样的问题。答案是from the source:
* ## Usage
*
* expression | date[:format]
*
* where `expression` is a date object or a number (milliseconds
* since UTC epoch) or an ISO string
* (https://www.w3.org/TR/NOTE-datetime) and `format` indicates which
* date/time components to
* include:
...
* In javascript, only the components specified will be respected
* (not the ordering,
* punctuations, ...) and details of the formatting will be dependent
* on the locale.
所以答案是,“因为format
不能按预期的方式工作。”
答案 1 :(得分:0)
我目前正在研究新的ng2-bootstrap datepicker,并将公开moment.js动力日期格式,因此您可以使用以下任何格式:http://momentjs.com/docs/#/displaying/
PS如果你想尽快得到它并获得更新,请加入https://www.hamsterpad.com/chat/ng2