Open artemik opened 7 years ago
All pipes implement PipeTransform
which has method transform(value: any, ...args: any[])
.
You can use it like this:
let a = new Date();
let b = (new DateFormatPipe()).transform(a, 'YYYY-MM-DD HH:mm');
console.log(a);
console.log(b);
Will output
Wed Aug 09 2017 19:52:18 GMT+0300 (Russia TZ 2 Standard Time)
2017-08-09 19:52
Also instead of creating a new instance you can provide pipe in parent module and inject in constructor (just like a service).
Don't forget to:
import { DateFormatPipe } from 'angular2-moment';
How do you amUtc from code?
How to use momentjs just in code? Not in templates.