'TimeZoneInfo.GetSystemTimeZones does not contain TimeZoneInfo.Local when current timezone is UTC
In my linux machine, where the time zone set to UTC.
[root@(none) /]# date
Tue Sep 22 16:11:12 UTC 2020
I used to run a program
TimeZoneInfo localZone = TimeZoneInfo.Local;
ReadOnlyCollection<TimeZoneInfo> zones = TimeZoneInfo.GetSystemTimeZones ();
foreach (TimeZoneInfo zoneVal in zones) {
if (localZone.StandardName == zoneVal.StandardName) {
Console.WriteLine("local zone found!!"); //this is not printing
}
}
This program works fine if I run with dotnet-core 2.1. But if I run it with mono 6.0.0.327, it is unable to find localZone in System Time Zones.
Is there any way to get it to work without changing the current timezone from UTC and without changing to dotnet?
Solution 1:[1]
Extending Matt's answer which was the one that finally helped me, below is my code snippet, the Id property is the key. You need to install the "TimeZoneConverter" NuGet. And the snippet below works in Windows & Linux with .NET Core 3.1:
var tz = TZConvert.GetTimeZoneInfo("Any TimeZone Name");
TimeZoneInfo tst = TimeZoneInfo.FindSystemTimeZoneById(tz.Id);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Daspuru |
