TimeZoneInfo.ConvertTimeFromUtc(DateTime, TimeZoneInfo) メソッド

定義

世界協定時刻 (UTC) を、指定されたタイム ゾーンの時刻に変換します。Converts a Coordinated Universal Time (UTC) to the time in a specified time zone.

public:
 static DateTime ConvertTimeFromUtc(DateTime dateTime, TimeZoneInfo ^ destinationTimeZone);
public static DateTime ConvertTimeFromUtc (DateTime dateTime, TimeZoneInfo destinationTimeZone);
static member ConvertTimeFromUtc : DateTime * TimeZoneInfo -> DateTime
Public Shared Function ConvertTimeFromUtc (dateTime As DateTime, destinationTimeZone As TimeZoneInfo) As DateTime

パラメーター

dateTime
DateTime

世界協定時刻 (UTC)。The Coordinated Universal Time (UTC).

destinationTimeZone
TimeZoneInfo

dateTime の変換先タイム ゾーン。The time zone to convert dateTime to.

戻り値

DateTime

変換先タイム ゾーンでの日付と時刻。The date and time in the destination time zone. destinationTimeZoneUtc の場合、Kind プロパティは Utc。それ以外の場合、Kind プロパティは UnspecifiedIts Kind property is Utc if destinationTimeZone is Utc; otherwise, its Kind property is Unspecified.

例外

dateTimeKind プロパティが Local です。The Kind property of dateTime is Local.

destinationTimeZonenullです。destinationTimeZone is null.

次の例では、世界協定時刻 (UTC) を中部標準時に変換します。The following example converts Coordinated Universal Time (UTC) to Central Time.

DateTime timeUtc = DateTime.UtcNow;
try
{
   TimeZoneInfo cstZone = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
   DateTime cstTime = TimeZoneInfo.ConvertTimeFromUtc(timeUtc, cstZone);
   Console.WriteLine("The date and time are {0} {1}.", 
                     cstTime, 
                     cstZone.IsDaylightSavingTime(cstTime) ?
                             cstZone.DaylightName : cstZone.StandardName);
}
catch (TimeZoneNotFoundException)
{
   Console.WriteLine("The registry does not define the Central Standard Time zone.");
}                           
catch (InvalidTimeZoneException)
{
   Console.WriteLine("Registry data on the Central Standard Time zone has been corrupted.");
}
Dim timeUtc As Date = Date.UtcNow
Try
   Dim cstZone As TimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time")
   Dim cstTime As Date = TimeZoneInfo.ConvertTimeFromUtc(timeUtc, cstZone)
   Console.WriteLine("The date and time are {0} {1}.", _
                     cstTime, _
                     IIf(cstZone.IsDaylightSavingTime(cstTime), _
                         cstZone.DaylightName, cstZone.StandardName))
Catch e As TimeZoneNotFoundException
   Console.WriteLine("The registry does not define the Central Standard Time zone.")
Catch e As InvalidTimeZoneException
   Console.WriteLine("Registry data on the Central Standard Time zone has been corrupted.")
End Try

注釈

変換を実行すると、 ConvertTimeFromUtc メソッドはタイムゾーンで有効な調整規則を適用し destinationTimeZone ます。When performing the conversion, the ConvertTimeFromUtc method applies any adjustment rules in effect in the destinationTimeZone time zone.

このメソッドの正確な動作は、 Kind 次の表に示すように、パラメーターのプロパティの値によっ dateTime て異なります。The precise behavior of this method depends on the value of the Kind property of the dateTime parameter, as the following table shows.

DateTime.Kind プロパティDateTime.Kind property 変換Conversion
DateTimeKind.Local をスロー ArgumentException します。Throws an ArgumentException.
DateTimeKind.Unspecified または DateTimeKind.UtcDateTimeKind.Unspecified or DateTimeKind.Utc 世界協定時刻 (UTC) から変換します。Converts from Coordinated Universal Time (UTC).

の変換 dateTime 結果が、より前または後の日付と時刻の値になる場合 DateTime.MinValue DateTime.MaxValue 、このメソッド DateTime.MinValue は、それぞれまたはを返し DateTime.MaxValue ます。If the conversion of dateTime results in a date and time value that is earlier than DateTime.MinValue or later than DateTime.MaxValue, this method returns DateTime.MinValue or DateTime.MaxValue, respectively.

適用対象

こちらもご覧ください