Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the default timezone for nestjs cron (@Cron) decorator

I am writing a cron to run at midnight every day in Indian Standard Time.

@Injectable()
export class CronService {

  @Cron("0 0 * * *")
  async midnightCron() {
    // implementation
  }

}

My instance is deployed in AWS Mumbai region.

I want to know if the @Cron decorator uses local time or UTC time for execution ?

like image 449
Vijay PD Avatar asked Oct 24 '25 06:10

Vijay PD


1 Answers

The cron package that NestJS uses just works based on the TZ environment variable if no timezone is passed to it when scheduling the task. This is a default environment variable that usually reflects the system's clock, but can be set to UTC to have Node's Date class function as if it were always in UTC time.

like image 187
Jay McDoniel Avatar answered Oct 26 '25 20:10

Jay McDoniel