0

我想以下一个格式显示日期: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>

这里有什么问题?

4

2 回答 2

0

我有同样的问题。这是来自源的答案:

* ## 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它没有按照你期望的方式工作。”

于 2016-07-13T13:12:15.210 回答
0

我目前正在开发新的 ng2-bootstrap 日期选择器,并将公开 moment.js 驱动的日期格式,因此您可以使用以下任何格式:http ://momentjs.com/docs/#/displaying/

PS 如果您想尽快获取并获取更新,请加入https://www.hamsterpad.com/chat/ng2

于 2016-07-22T18:27:54.370 回答