DateTimeOffset.Implicit(DateTime to DateTimeOffset) DateTimeOffset.Implicit(DateTime to DateTimeOffset) DateTimeOffset.Implicit(DateTime to DateTimeOffset) Operator

定義

暗黙的な変換を定義、DateTimeオブジェクトをDateTimeOffsetオブジェクト。Defines an implicit conversion of a DateTime object to a DateTimeOffset object.

public:
 static operator DateTimeOffset(DateTime dateTime);
public static implicit operator DateTimeOffset (DateTime dateTime);
static member op_Implicit : DateTime -> DateTimeOffset

パラメーター

dateTime
DateTime DateTime DateTime

変換対象のオブジェクト。The object to convert.

戻り値

変換後のオブジェクト。The converted object.

例外

オフセットを適用した結果の世界協定時刻 (UTC) の日時が MinValue 未満です。The Coordinated Universal Time (UTC) date and time that results from applying the offset is earlier than MinValue.

- または --or- オフセットを適用した結果の UTC 日時が MaxValue を超えています。The UTC date and time that results from applying the offset is later than MaxValue.

注釈

Implicitメソッドにより、自動的に変換するコンパイラをDateTimeオブジェクトをDateTimeOffsetせずに明示的なキャスト演算子 (c#) または (Visual Basic) での変換関数の呼び出しオブジェクト。The Implicit method enables the compiler to automatically convert a DateTime object to a DateTimeOffset object without an explicit casting operator (in C#) or a call to a conversion function (in Visual Basic). データの損失を伴わないをスローしない拡大変換を定義、OverflowExceptionします。It defines a widening conversion that does not involve data loss and does not throw an OverflowException. Implicitメソッドは、次の指定可能なコード。The Implicit method makes code such as the following possible:

DateTimeOffset timeWithOffset; 
timeWithOffset = new DateTime(2008, 7, 3, 18, 45, 0);
Console.WriteLine(timeWithOffset.ToString());

timeWithOffset = DateTime.UtcNow;
Console.WriteLine(timeWithOffset.ToString());

timeWithOffset = DateTime.SpecifyKind(DateTime.Now, 
                                      DateTimeKind.Unspecified);
Console.WriteLine(timeWithOffset.ToString());

timeWithOffset = new DateTime(2008, 7, 1, 2, 30, 0) +
                       new TimeSpan(1, 0, 0, 0);
Console.WriteLine(timeWithOffset.ToString());
 
timeWithOffset = new DateTime(2008, 1, 1, 2, 30, 0)
Console.WriteLine(timeWithOffset.ToString());
// The example produces the following output if run on 3/20/2007 
// at 6:25 PM on a computer in the U.S. Pacific Daylight Time zone:
//       7/3/2008 6:45:00 PM -07:00
//       3/21/2007 1:25:52 AM +00:00
//       3/20/2007 6:25:52 PM -07:00
//       7/2/2008 2:30:00 AM -07:00
//       1/1/2008 2:30:00 AM -08:00
//
// The last example shows automatic adaption to the U.S. Pacific Time 
// for winter dates.
Dim timeWithOffset As DateTimeOffset 
timeWithOffset = #07/03/2008 6:45PM#
Console.WriteLine(timeWithOffset.ToString())

timeWithOffset = Date.UtcNow
Console.WriteLine(timeWithOffset.ToString())

timeWithOffset = Date.SpecifyKind(Date.Now, DateTimeKind.Unspecified)
Console.WriteLine(timeWithOffset.ToString())

timeWithOffset = #07/01/2008 2:30AM# + New TimeSpan(1, 0, 0, 0)
Console.WriteLine(timeWithOffset.ToString())
  
timeWithOffset = #01/01/2008 2:30AM#
Console.WriteLine(timeWithOffset.ToString())
' The example produces the following output if run on 3/20/2007 
' at 6:25 PM on a computer in the U.S. Pacific Daylight Time zone:
'       7/3/2008 6:45:00 PM -07:00
'       3/21/2007 1:25:52 AM +00:00
'       3/20/2007 6:25:52 PM -07:00
'       7/2/2008 2:30:00 AM -07:00
'       1/1/2008 2:30:00 AM -08:00
'
' The last example shows automatic adaption to the U.S. Pacific Time
' for winter dates.

このメソッドは、DateTimeOffsetコンス トラクター。This method is equivalent to the DateTimeOffset constructor. 結果のオフセットDateTimeOffsetオブジェクトの値に依存、DateTime.Kindのプロパティ、dateTimeパラメーター。The offset of the resulting DateTimeOffset object depends on the value of the DateTime.Kind property of the dateTime parameter:

この演算子を同等のメソッドは、します。 DateTimeOffset.DateTimeOffset(DateTime)The equivalent method for this operator is DateTimeOffset.DateTimeOffset(DateTime)

適用対象