@ccmos/nestjs-moment
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i @ccmos/nestjs-moment

Weekly Downloads

668

Version

0.1.0

License

MIT

Unpacked Size

20.4 kB

Total Files

22

Last publish

Collaborators

  • mosluce