@ccmos/nestjs-moment

[moment](https://momentjs.com/) module for [NestJS](https://github.com/nestjs/nest).

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
@ccmos/nestjs-moment
0.1.0a year agoa year agoMinified + gzip package size for @ccmos/nestjs-moment in KB

Readme

@ccmos/nest-moment
moment module for NestJS.
moment-timezone included

Install

npm i @ccmos/nestjs-moment

Usage

// module
@Module({
  imports: [
    MomentModule.forRoot({
      tz: 'Asia/Taipei',
    }),
  ],
  providers: [TimeService],
})
export class AppModule {}

// service or provider
@Injectable()
export class TimeService {
  constructor(
    @Inject(MOMENT) moment: Moment,
    @Inject(MOMENT_TZ) mtz: MomentTz
  ) {}

  fn() {
    moment().format('YYYYMMDD'); // ...

    mtz().format('YYYYMMDD');
    // or
    mtz('2021-03-26T08:00:00.000Z').format('YYYYMMDD');
    // or
    mtz(new Date(), 'Asia/Tokyo').format('YYYYMMDD');
  }
}