Problems with FindSystemTimeZoneById in Web.API .NET Core in Docker (Linux)

0

Scenario:

I'm migrating a WebAPI to .NET Core, in Windows it's running normally.

Problem

When I'm running on Docker (Linux) (docker-compose) I'm having the following problem:

  

"The time zone ID 'W. Europe Standard Time' was not   found on the local computer. "

Code where it occurs:

public static DateTime ConvertDateToLanguage(DateTime dDateLocal)
{
    var sqlServerRepository = new SqlServerRepository();
    var cstZone =
        TimeZoneInfo.FindSystemTimeZoneById(
            sqlServerRepository.GetImpostazioniSkin().FirstOrDefault()?.FusoOrario ?? string.Empty);
    var cstTime = TimeZoneInfo.ConvertTimeFromUtc(dDateLocal.ToUniversalTime(), cstZone);
    return cstTime;
}
    
asked by anonymous 30.12.2017 / 12:17

1 answer

0

Going back in time a bit I remembered that Linux has the TimeZone nomenclature other than Windows

In Windows we have Eastern Standard Time

On Linux we have America / New_York

I found it interesting that you have a conversion tool:

It is possible to convert using TimeZoneConverter

Example:

string tz = TZConvert.IanaToWindows("America/New_York");
// Result:  "Eastern Standard Time"

string tz = TZConvert.WindowsToIana("Eastern Standard Time");
// result:  "America/New_York"

string tz = TZConvert.WindowsToIana("Eastern Standard Time", "CA");
// result:  "America/Toronto"

So, using America / New York for example worked.

Extract the information here:

link

    
30.12.2017 / 12:38