Ngx-Moment Moment.Js Pipes For Angular
If you think of using momentjs in your app to Parse, validate, manipulate, and display dates and times in JavaScript, Angular-moment is an awesome module for that.
Last updated: {{myDate | amTimeAgo}} // Prints Last updated: a few seconds ago Last updated: {{myDate | amCalendar}} // Prints Last updated: Today at 14:00 (default referenceTime is today by default) Last updated: {{myDate | amCalendar:{sameDay:'[Same Day at] h:mm A'} }} // Prints Last updated: Same Day at 2:00 PM
How to Add Angular-Moment to your Angular app:
npm install --save moment ngx-moment
This adds, moment.js module and ngx-moment to your node_modules. To you it, import it to your app.module or feature module as below:
import { MomentModule } from 'ngx-moment'; @NgModule({ imports: [ MomentModule ] })
It's a piping module, so all you need to do in your template is add as a pipe:
Last updated: {{myDate | amTimeAgo:true}}
``` For more on this module: https://github.com/urish/ngx-moment