Ich habe eine aspnet Kern app asp mvc App, die Zeitzone Konvertierungen zwischen UTC, Central Time Zone und Singapore Standard Time tun muss. Ich habe dies in meiner Windows-Entwicklungsumgebung arbeiten mit der TimeZoneInfo.FindSystemTimeZoneById
Methode, um eine Zeitzone Instanz und Übergabe dieser Zeitzone Instanz in TimeZoneInfo.ConvertTime
, um die Zeit für die gewünschte Zeitzone zu erhalten. Allerdings, wenn ich die Web-App zu CentOS7 bereitstellen erhalte ich die Fehlermeldung:dotnet core crossplatform (Windows & CentOS) Zeitzonenumrechnung Fehler
"Could not find file '/usr/share/zoneinfo/Central Standard Time'."
Was muss ich tun dies auf beiden Plattformen zur Arbeit zu kommen?
public TimeZoneInfo TimeZoneInstance
{
get
{
if (_timeZoneInstance == null)
{
try
{
_timeZoneInstance = TimeZoneInfo.FindSystemTimeZoneById(TimeZone);
}
catch
{
TimeZone = "Central Standard Time";
_timeZoneInstance = TimeZoneInfo.FindSystemTimeZoneById(TimeZone);
}
}
return _timeZoneInstance;
}
private set { _timeZoneInstance = value; }
}
public DateTime? GetUserTime(DateTime? utcTime = null)
{
if (utcTime == null)
return utcTime;
return TimeZoneInfo.ConvertTime(DateTime.SpecifyKind(utcTime.Value, DateTimeKind.Utc), TimeZoneInfo.Utc, TimeZoneInstance);
}
public DateTime? GetUtcTime(DateTime? localTime)
{
if (localTime == null)
return localTime;
return TimeZoneInfo.ConvertTime(localTime.Value, TimeZoneInstance, TimeZoneInfo.Utc);
}