英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论