gpt4 book ai didi

date - 使用管道将日期格式化为 dd/MM/yyyy

转载 作者:太空狗 更新时间:2023-10-29 16:44:12 30 4
gpt4 key购买 nike

我正在使用 date 管道来格式化我的日期,但如果没有解决方法,我就是无法获得我想要的确切格式。我对管道的理解有误还是根本不可能?

//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();
}
}

plnkr view

最佳答案

Angular 2.0.0-rc.2 中修复的管道日期格式错误,this Pull Request .

现在我们可以按照常规方式进行:

{{valueDate | date: 'dd/MM/yyyy'}}

例子:

当前版本:

Example Angular 13


旧版本:

Example Angular 8.x.x

Example Angular 7.x

Example Angular 6.x

Example Angular 4.x

Example Angular 2.x


More info in documentation DatePipe

关于date - 使用管道将日期格式化为 dd/MM/yyyy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35754586/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com