Good afternoon, I need help formatting a date in angular8. I have searched and found that it can be used (DatePipe) but when injecting it in the constructor I get an error:
StaticInjectorError(AppModule)[CrearUsuarioComponent -> DatePipe]:
I don't know what the error is
my code is the following:
import { DatePipe } from '@angular/common';
constructor(pprivate datePipe: DatePipe){}
obtenerFecha(fecha){
this.datePipe.transform(fecha,'dd/MM/yyyy');
this.fechaform=this.datePipe.transform(fecha, 'dd/MM/yyyy');
console.log(this.fechaform);
}
Pipes are mainly intended to be used in the template, to format a date for example you can use this Angular pipe.
If you want to use it in the component you must add it to your providers in your module
VALID ANSWER FOR ANGULARJS or ANGULAR 1.X put here because the question Format date in Angular? by rejecting twice
Type filters
Date
allow you to print dates in the desired format.If you need to do it inside a variable, in code, you can do it with $filter('date')