In AngularJS, I am able to use filters (pipes) inside of services and controllers using syntax similar to this:
$filter(\'date\')(myDate, \'yyyy-MM-dd\');
>
You can use formatDate() to format the date in services or component ts. syntax:-
formatDate(value: string | number | Date, format: string, locale: string, timezone?: string): string
import the formatDate() from common module like this,
import { formatDate } from '@angular/common';
and just use it in the class like this ,
formatDate(new Date(), 'MMMM dd yyyy', 'en');
You can also use the predefined format options provided by angular like this ,
formatDate(new Date(), 'shortDate', 'en');
You can see all other predefined format options here ,
https://angular.io/api/common/DatePipe