如何在 Angular2 中为日期添加天数?
How to add days to a date in Angular2?
我只想创建一个从现在起 3 天的日期,用于打字稿 angular 组件。
我看过 Angular2 moment but this seems only to relate to pipes. Although I did see 关于在代码中使用管道的内容,看起来有点老套...
也许我遗漏了什么,因为这应该很简单?!
谢谢
date: Date;
ngOnInit() {
this.date = new Date();
this.date.setDate( this.date.getDate() + 3 );
}
然后您可以使用日期管道在 HTML
中很好地显示日期
{{ date | date }}
这样呈现:
Sep 25, 2017
我只想创建一个从现在起 3 天的日期,用于打字稿 angular 组件。
我看过 Angular2 moment but this seems only to relate to pipes. Although I did see
也许我遗漏了什么,因为这应该很简单?!
谢谢
date: Date;
ngOnInit() {
this.date = new Date();
this.date.setDate( this.date.getDate() + 3 );
}
然后您可以使用日期管道在 HTML
中很好地显示日期{{ date | date }}
这样呈现:
Sep 25, 2017