angular moment code example

Example 1: angular moment

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

Example 2: moment use in angular

npm install --save moment
import * as moment from 'moment';
...
let myMoment: moment.Moment = moment("someDate");

Example 3: ngx moment

npm install --save moment ngx-moment
...
import { MomentModule } from 'ngx-moment';
 
@NgModule({
  imports: [
    MomentModule
  ]
})

Example 4: moment.js format

moment("20111031", "YYYYMMDD").fromNow(); // 9 years ago
moment("20120620", "YYYYMMDD").fromNow(); // 8 years ago
moment().startOf('day').fromNow();        // 13 hours ago
moment().endOf('day').fromNow();          // in 11 hours
moment().startOf('hour').fromNow();       // 4 minutes ago