我想把当前的数据转换成'yyyy-MM-dd'
种格式.ts文件.我认为通过使用数据管道可以很容易地做到这一点.如何在typescript中实现这一点.
In template:
{{date | date:'yyyy-MM-dd'}}
How to convert in this format 100 in typescript.
现在我用这个来获取当前日期.
this.date = new Date();
但需要将其转换为给定的格式.
我想把当前的数据转换成'yyyy-MM-dd'
种格式.ts文件.我认为通过使用数据管道可以很容易地做到这一点.如何在typescript中实现这一点.
In template:
{{date | date:'yyyy-MM-dd'}}
How to convert in this format 100 in typescript.
现在我用这个来获取当前日期.
this.date = new Date();
但需要将其转换为给定的格式.
日期可以通过使用Datepipe在typescript中转换为这种格式
import { DatePipe } from '@angular/common'
...
constructor(public datepipe: DatePipe){}
...
myFunction(){
this.date=new Date();
let latest_date =this.datepipe.transform(this.date, 'yyyy-MM-dd');
}
只需在应用程序的"提供者"数组中添加Datepipe.单元T.像这样:
import { DatePipe } from '@angular/common'
...
providers: [DatePipe]