Created
May 11, 2017 00:10
-
-
Save leocaseiro/25282a4dcc248579789e2304937d6bc2 to your computer and use it in GitHub Desktop.
Angular 4 date-fns Pipe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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