import { Pipe , PipeTransform } from '@angular/core' ; import * as moment from 'moment' ; see http example @ Pipe ( { name : 'toDate' } ) export class MomentDatePipe implements PipeTransform { transform ( value ? , formatString = 'YYYY-MM-DD HH:mm' ) { if ( value ) { let d = ( value instanceof Date ) ? moment ( value ) : value ; if ( formatString === 'fn' ) return moment ( value ) . fromNow ( ) ; return moment ( value ) . format ( formatString ) ; } else { return '' ; } } }