If you want to convert current data into ‘yyyy-MM-dd’ format in .ts file. just see this tuto :

In template: (.html)

{{date  | date:'yyyy-MM-dd'}}

in typescript: (.ts)

The date can be converted in typescript to this format ‘yyyy-MM-dd’ by using Datepipe

import { DatePipe } from '@angular/common'
constructor(public datepipe: DatePipe){}
 this.date=new Date();
 let latest_date =this.datepipe.transform(this.date, 'yyyy-MM-dd');

and just add Datepipe in ‘providers’ array of app.module.ts. Like this:

import { DatePipe } from '@angular/common'
providers: [DatePipe]

Read also : How to get the current year using typescript in angular 6

Laisser un commentaire