Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use momentjs in code #158

Open
artemik opened this issue Aug 2, 2017 · 2 comments
Open

How to use momentjs in code #158

artemik opened this issue Aug 2, 2017 · 2 comments

Comments

@artemik
Copy link

artemik commented Aug 2, 2017

How to use momentjs just in code? Not in templates.

@tplk
Copy link

tplk commented Aug 9, 2017

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';

@jcbowyer
Copy link

How do you amUtc from code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants