angular moment
snippet in javascript

angular moment

user5488

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

ngx moment

user8580

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

moment.js format

user3908

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