私は、UTC、中央タイムゾーン、シンガポール標準時のタイムゾーン変換を行う必要があるdotnet core asp.net mvcアプリケーションを持っています。私はこれを私のWindows開発環境で、TimeZoneInfo.FindSystemTimeZoneById
メソッドを使用してタイムゾーンインスタンスを設定し、そのタイムゾーンインスタンスをTimeZoneInfo.ConvertTime
に渡して、目的のタイムゾーンの時間を取得します。私はCentOS7にWebアプリケーションを展開するときしかし、私はエラーを取得する:dotnet core crossplatform(Windows&CentOS)タイムゾーン変換エラー
"Could not find file '/usr/share/zoneinfo/Central Standard Time'."
私は、これは両方のプラットフォーム上で動作するように取得するために行うには何が必要ですか? * nixの上の.NETのコアは、IANAのタイムゾーンを使用しながら、Windows上
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);
}