c# - Azure 函数 (C#) : get time zone ids (NodaTime)

标签 c# datetime azure-functions utc nodatime

我有一个时间触发的 Azure 函数。 Azure Function 每次都在凌晨 00:00(本地时间)某处启动。我想要实现的是找到时区字符串(例如 Europe/London),当 Azure Function 正在运行时,该时区当前为 00:00 am。

即,我提供了一个 UTC 值,它为我提供了当前本地时间上午 00:00 的所有时区 ID。

我如何使用 NodaTime 实现这一点?

最佳答案

一个比你的稍微简单的版本,如果你总是想检查午夜:

static List<string> GetTimeZonesAtMidnight(Instant instant) =>
    // Extension method in NodaTime.Extensions.DateTimeZoneProviderExtensions
    DateTimeZoneProviders.Tzdb.GetAllZones()
        .Where(zone => instant.InZone(zone).TimeOfDay == LocalTime.Midnight)
        .Select(zone => zone.Id)
        .ToList();

如果您需要检查非午夜值,请传入 LocalTime:

static List<string> GetTimeZonesAtMidnight(Instant instant, LocalTime timeOfDay) =>
    // Extension method in NodaTime.Extensions.DateTimeZoneProviderExtensions
    DateTimeZoneProviders.Tzdb.GetAllZones()
        .Where(zone => instant.InZone(zone).TimeOfDay == timeOfDay)
        .Select(zone => zone.Id)
        .ToList();

关于c# - Azure 函数 (C#) : get time zone ids (NodaTime),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56328411/

相关文章:

php - 如何将 PHP 日期中的 M 转换为 m

javascript - 如何使用 azure 函数和 cosmos Node sdk 检查 cosmosDB 中的项目是否已过期?

c# - 正确包含一个带有 .NET 核心的项目

c# - 性能:从泛型派生的类型

c# - 日期时间格式错误 C#、Oracle

c# - 如何使用 Dateformat ISO 8601 创建 .NET CultureInfo?

c# - 如何找到日期字符串的确切格式?

c# - bool 值不变

c# - 在 Azure 函数中使用 RestSharp 调用 HTTPS 会给出 "The SSL connection could not be established"

c# - 带有 .net core 2 类库的 Azure 函数