[英]How to pass timezone to Azure function with timer trigger
I created an azure function that I need to run at 11 AM EST time.我创建了一个需要在美国东部标准时间上午 11 点运行的 azure 函数。 I understand the timer triggers use UTC however is there a way to pass in 11 AM to the run function for readability purposes?我知道计时器触发器使用 UTC 但是有没有办法将上午 11 点传递给运行函数以提高可读性?
For example here is my run method, is it possible to pass 11 AM where the X sits and specify a timezone?:例如,这是我的运行方法,是否可以通过 X 所在的上午 11 点并指定时区?:
public static void Run([TimerTrigger("0 0 X * * *")]TimerInfo myTimer, TraceWriter log)
Azure Function based on Web app sandbox.基于 Web 应用沙箱的 Azure Function。 Web app need you to set the timezone in env settings first. Web 应用程序需要您首先在 env 设置中设置时区。 The timetrigger attribute is the declaration part of the function. timetrigger 属性是函数的声明部分。 The environment variables will be checked here.这里将检查环境变量。 If you do not set the environment variables about the time zone in advance, it will be processed according to the default UTC time.如果没有提前设置时区的环境变量,会按照默认的UTC时间处理。
The env variable comes from different place when run on local and run on azure.在本地运行和在 azure 上运行时,env 变量来自不同的地方。
For example, if you want to set EST time.例如,如果要设置 EST 时间。
On local, you need to set it in local.settings.json.在本地,您需要在 local.settings.json 中进行设置。 like this:像这样:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"WEBSITE_TIME_ZONE": "US Eastern Standard Time"
}
}
On Azure, set the time zone in this place(dont forget to save the changes):在 Azure 上,在此位置设置时区(不要忘记保存更改):
From this doc , EST = GMT - 5. So in your case, if you are in default time zone, you can set the CRON as 0 0 6 * * *
.从这个 doc , EST = GMT - 5. 所以在你的情况下,如果你在默认时区,你可以将 CRON 设置为0 0 6 * * *
。 Since the hour cannot be negative.由于小时不能为负。 So it is valid for your situation, but not necessarily applicable to other situations.所以它对你的情况有效,但不一定适用于其他情况。 I suggest you use the method I recommended at the beginning.我建议你使用我一开始推荐的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.