moment js date format angular 2 code example

Example 1: angular moment

npm install --save moment
...
import * as moment from 'moment';

Example 2: angular moment pipe timeAgo

Ref: https://github.com/urish/ngx-moment
Import MomentModule into your app's modules:

import { MomentModule } from 'ngx-moment';

@NgModule({
  imports: [
    MomentModule
  ]
})
If you would like to supply any NgxMomentOptions that will be made available to the pipes you can also use:

import { MomentModule } from 'ngx-moment';

@NgModule({
  imports: [
    MomentModule.forRoot({
      relativeTimeThresholdOptions: {
        'm': 59
      }
    })
  ]
})