Assuming you are using Angular, you may import DatePipe, or FormatDate into your component.ts to handle that. You may read more about the various date/time formats you can pass as the parameters.
1) DatePipe:
import { DatePipe } from '@angular/common';
export class SampleComponent implements OnInit {
constructor(private datePipe: DatePipe) {}
transformDate(date) {
return this.datePipe.transform(date, 'yyyy-MM-dd');
}
}
Do not forget to add DatePipe to your providers in your module.
providers: [DatePipe]
2) formatDate:
import { formatDate } from '@angular/common';
export class SampleComponent implements OnInit {
constructor(@Inject(LOCALE_ID) private locale: string) {}
transformDate(date) {
return formatDate(date, 'yyyy-MM-dd', this.locale);
}
}