Step 1 :
app.module.ts
import {DatePipe} from ‘@angular/common’;
.
.
.
providers: [DatePipe]
Step 2 :
demo.component.ts
import { DatePipe } from ‘@angular/common’;
.
.
constructor(private datePipe: DatePipe) {}
ngOnInit() {
var date = new Date();
console.log(this.datePipe.transform(date,”yyyy-MM-dd”)); //output : 2018-02-13
}