DEV Community

Cover image for Azure Functions Tips: change the time zone in your Azure Function using configuration
Massimo Bonanni
Massimo Bonanni

Posted on

Azure Functions Tips: change the time zone in your Azure Function using configuration

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);
}


Enter fullscreen mode Exit fullscreen mode

and you make a GET request, you receive:

The function response

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.

tzutil command output

  • 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:

The WEBSITE_TIME_ZONE configuration in Azure Portal

and we make another request to the function, we have the following response:

The function response after time zone change

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)