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

Asked

Viewed 364 times

0

Setting:

I am migrating a Webapi to . NET Core, on Windows is running normally.

Problem

When I am running on Docker (Linux) (Docker-Compose) I am having the following problem:

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

Code where 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;
}

1 answer

0


Going back in time a little remembered that Linux has Timezone nomenclature different from Windows

In Windows we have for example Eastern Standard Time

On Linux we have America/New_york

I found it interesting that has a tool that makes the conversion:

It is possible to perform the conversion 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"

Therefore, using America/New York for example worked.

I extracted the information from here:

https://stackoverflow.com/questions/17348807/how-to-translate-between-windows-and-iana-time-zones

Browser other questions tagged

You are not signed in. Login or sign up in order to post.