In AngularJS, I am able to use filters (pipes) inside of services and controllers using syntax similar to this:
$filter(\'date\')(myDate, \'yyyy-MM-dd\');
>
recommend using DI approach from other answers instead of this approach
You should be able to use the class directly
new DatePipe().transform(myDate, 'yyyy-MM-dd');
For instance
var raw = new Date(2015, 1, 12);
var formatted = new DatePipe().transform(raw, 'yyyy-MM-dd');
expect(formatted).toEqual('2015-02-12');