nestjs cron (@Cron) 装饰器的默认时区是什么?

huangapple go评论70阅读模式
英文:

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

问题

@Cron装饰器是使用UTC时间执行的。

英文:

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 ?

答案1

得分: 1

cron是NestJS使用的包,如果在调度任务时没有传递时区,它将基于TZ环境变量正常工作。这是一个默认的环境变量,通常反映了系统的时钟,但可以设置为UTC,以使Node的Date类始终按照UTC时间运行。

英文:

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.

huangapple
  • 本文由 发表于 2023年6月12日 18:42:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76455855.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定