Skip to content

Instantly share code, notes, and snippets.

@ALEXOTANO
Last active August 14, 2019 20:29
Show Gist options
  • Save ALEXOTANO/77ce674f79b2f885523c6cf3fd5bba40 to your computer and use it in GitHub Desktop.
Save ALEXOTANO/77ce674f79b2f885523c6cf3fd5bba40 to your computer and use it in GitHub Desktop.
Formatear Fechas Angular
Use DatePipe pipe
date_expression | date[:format]

in your case

{{ date_expression | date:'dd-MM-yy' }}

How to use the pipe inside the component :

NgModule({
  ....
  providers: [DatePipe]
})

or

@Component({
   ....
  providers: [DatePipe]
})

In you component set it as a date variable

constructor(private datePipe: DatePipe) {
}

ngOnInit() {
    this.date = this.datePipe.transform(new Date(), 'dd-MM-yy');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment