import { Pipe , PipeTransform } from "@angular/core" ; @ Pipe ( { name : "timestamp" } ) export class TimestampPipe implements PipeTransform { private normalize ( num ) { return `${ num > 9 ? num : "0" + num }` ; } transform ( value , format ) { let date = new Date ( value * 1000 ) ; if ( format === "time" ) { let hours = date . getHours ( ) ; let minutes = date . getMinutes ( ) ; return `${ this . normalize ( hours ) }:${ this . normalize ( minutes ) }` ; } else if ( format === "date" ) { let month = date . getMonth ( ) + 1 ; let day = date . getDate ( ) ; return `${ this . normalize ( month ) }-${ this . normalize ( day ) }` ; } else { let month = date . getMonth ( ) + 1 ; let day = date . getDate ( ) ; let hours = date . getHours ( ) ; let minutes = date . getMinutes ( ) ; return `${ this . normalize ( month ) }-${ this . normalize ( day ) } ${ this . normalize ( hours ) }:${ this . normalize ( minutes ) }` ; } } }