date pipe mm/dd/yyyy angular code example
Example 1: ts change date format
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');
}
Example 2: angular date pipe
<p>{{myDate | date: 'dd-MM-yyyy'}}</p>
myDate: Date = new Date();
Example 3: angular get current date yyyy-mm-dd
import { DatePipe } from '@angular/common';
@Component({
templateUrl: './name.component.html',
styleUrls: ['./name.component.scss'],
providers: [DatePipe]
})
myDate = new Date();
constructor(private datePipe: DatePipe){
this.myDate = this.datePipe.transform(this.myDate, 'yyyy-MM-dd');
}