使用管道将日期格式设置为dd/MM/yyyy [英] Format date as dd/MM/yyyy using pipes
本文介绍了使用管道将日期格式设置为dd/MM/yyyy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用date
管道设置日期格式,但是如果没有解决方法,我只是无法获得所需的确切格式.我是错误地理解管道还是只是不可能?
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();
}
}
推荐答案
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'}}
示例:
当前版本:
旧版本:
这篇关于使用管道将日期格式设置为dd/MM/yyyy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文