Skip to content

Instantly share code, notes, and snippets.

@leocaseiro
Created May 11, 2017 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leocaseiro/25282a4dcc248579789e2304937d6bc2 to your computer and use it in GitHub Desktop.
Save leocaseiro/25282a4dcc248579789e2304937d6bc2 to your computer and use it in GitHub Desktop.
Angular 4 date-fns Pipe
import { Pipe, PipeTransform } from '@angular/core';
import * as format from 'date-fns/format';
@Pipe({
name: 'dateFnsFormat'
})
export class DateFnsFormatPipe implements PipeTransform {
transform(value, args?) {
return format(value, args);
}
}
import { Component } from '@angular/core';
import { DateFnsFormatPipe } from './date-format.pipe';
@Component({
template: `{{meetupTime | dateFnsFormat:'DD/MM/YYYY HH:mm:ss'}}`,
providers: [DateFnsFormatPipe]
})
export class UsageComponent {
meetupTime = '2017-05-21 17:30:00';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment