Reputation: 147
I'm running an Azure Functions project locally on Mac OS. My issue is using the TimeZoneInfo.FindSystemTimeZoneById(String)
Method.
On input of 'Mountain Standard Time', which is included on Windows Platforms according to this link. This is fine when pushed to the hosting platform which is Windows, but on my local machine an error is thrown.
How do I handle this locally?
Upvotes: 2
Views: 991
Reputation: 241758
The IDs and data used with TimeZoneInfo
are platform dependent:
tzutil.exe
command, Win32 APIs, and are sourced from the Registry.
"Mountain Standard Time"
TZ
environment variable, timedatectl
, sudo dpkg-reconfigure tzdata
, sudo systemsetup -settimezone timezone
, and other platform-specific utilities. The data is sourced from the IANA tz database.
"America/Denver"
Thus you can change your code to the following, which will run on Linux and Mac OSX.
TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById("America/Denver");
If you cannot change the identifiers used in your application, or are designing your application to be cross-platform and need to work with both sets of identifiers, then use my TimeZoneConverter library:
// Either of these will work on any platform
TimeZoneInfo tzi = TZConvert.GetTimeZoneInfo("Mountain Standard Time");
TimeZoneInfo tzi = TZConvert.GetTimeZoneInfo("America/Denver");
See also the "Time Zone Databases" section of the timezone tag wiki.
Upvotes: 4