Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@ccmos/nestjs-moment

mosluce2.3kMIT0.1.0TypeScript support: included

moment module for NestJS.

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');
  }
}