即使在更改网站时区后,Azure 函数输出路径也会返回 UTC 时间?

Azure functions output path returning UTC time even after changing Website time zone?

我已将 Azure 函数配置为使用绑定中的日期时间函数将文件输出到具有当前日期的 Blob 容器,但它正在创建一个 UTC 日期文件夹。

我什至将 WEBSITE_TIME_ZONE 更改为引用列表 here 的本地时间,但当我需要本地时间时仍会在 blob 中创建 UTC 日期文件夹。

我的绑定码是:

{
"connection": "AzureWebJobsStorage",
      "name": "Blobstr3",
      "path": "outcontainer/{datetime:ddMMyyyy}/{rand-guid}.txt",
      "direction": "out",
      "type": "blob"
    }

如果有人能帮我解决这个问题就好了?

本地时间没有绑定表达式。

官方Azure Functions binding expression patterns声明:

The binding expression DateTime resolves to DateTime.UtcNow.

要使用本地时间,您必须自己保存到 blob 或在运行时使用绑定(再次来自 Azure Functions binding expression patterns):

Binding at runtime

In C# and other .NET languages, you can use an imperative binding pattern, as opposed to the declarative bindings in function.json and attributes. Imperative binding is useful when binding parameters need to be computed at runtime rather than design time. To learn more, see the C# developer reference or the C# script developer reference.

下面是 Develop C# class library functions using Azure Functions

中的操作示例

Single attribute example

The following example code creates a Storage blob output binding with blob path that's defined at run time, then writes a string to the blob.


public static class IBinderExample
{
    [FunctionName("CreateBlobUsingBinder")]
    public static void Run(
        [QueueTrigger("myqueue-items-source-4")] string myQueueItem,
        IBinder binder,
        ILogger log)
    {
        log.LogInformation($"CreateBlobUsingBinder function processed: {myQueueItem}");
        using (var writer = binder.Bind<TextWriter>(new BlobAttribute(
                    $"samples-output/{myQueueItem}", FileAccess.Write)))
        {
            writer.Write("Hello World!");
        };
    }
}