我有一个时间触发的 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/