如何使用管道在角度2中格式化dd / MM / yyyy的日期? [英] How to format date as dd/MM/yyyy in Angular 2 using pipes?
本文介绍了如何使用管道在角度2中格式化dd / MM / yyyy的日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用日期管道来格式化日期,但是我无法获得所需的确切格式,而无需解决方法。我理解管道错误或是不可能吗?
I'm using the date pipe to format my date, but I just can't get the exact format I want without a workaround. Am I understanding pipes wrongly or is just not possible?
//our root app component
import {Component} from 'angular2/core'
@Component({
selector: 'my-app',
providers: [],
template: `
<div>
<h2>Hello {{name}}</h2>
<h3>{{date | date: 'ddMMyyyy'}}, should be
{{date | date: 'dd'}}/{{date | date:'MM'}}/{{date | date: 'yyyy'}}</h3>
</div>
`,
directives: []
})
export class App {
constructor() {
this.name = 'Angular2'
this.date = new Date();
}
}
推荐答案
管道日期格式错误修正在角度2.0 .0-rc.2,此推送请求。
Pipe date format bug fixed in Angular 2.0.0-rc.2, this Pull Request.
现在我们可以通过常规的方法:
Now we can do the conventional way:
{{valueDate | date: 'dd/MM/yyyy'}}
这篇关于如何使用管道在角度2中格式化dd / MM / yyyy的日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文