When you run your function in a Function App, the time zone of your code is always UTC
. So, for example, if you deploy the following Http Trigger Function in West US
:
[FunctionName("GetTime")]
public IActionResult Run(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "time")] HttpRequest req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
string responseMessage = $"Time of the server : {DateTimeOffset.Now}";
return new OkObjectResult(responseMessage);
}
and you make a GET request, you receive:
The time of the server is, evidently, UTC
.
Sometimes, you need to have a specific time zone in your code no matter what region you are using.
To force the time zone in your Function app, you can change the Function App configuration and set the WEBSITE_TIME_ZONE
value.
The value you can use in this setting depends on the OS you are choosing for the Function App:
- Windows: the setting is supported in all plans and the value you can use is one of the timezone you can retrieve using the
tzutil.exe /L
command.
- Linux: the setting is supported only on Premium and Dedicated plan (not in the Consumption) and the values you can use are the time zone in the TZ identifier list.
If we set the WEBSITE_TIME_ZONE
configuration with the 'W. Europe Standard Time' value as following:
and we make another request to the function, we have the following response:
As you can see the time zone of the server is changed.
Obviously, this configuration also impacts the Timer Trigger CRON configurations.
Top comments (0)