DateTimeOffset.Implicit(DateTime to DateTimeOffset) 연산자

정의

DateTime 개체를 DateTimeOffset 개체로 변환하는 암시적 변환을 정의합니다.

public:
 static operator DateTimeOffset(DateTime dateTime);
public static implicit operator DateTimeOffset (DateTime dateTime);
static member op_Implicit : DateTime -> DateTimeOffset
Public Shared Widening Operator CType (dateTime As DateTime) As DateTimeOffset

매개 변수

dateTime
DateTime

변환할 개체입니다.

반환

변환된 개체입니다.

예외

오프셋을 적용한 결과 UTC(협정 세계시) 날짜 및 시간이 DateTimeOffset.MinValue보다 낮습니다.

또는

오프셋을 적용한 결과 UTC 날짜 및 시간은 DateTimeOffset.MaxValue보다 낮습니다.

설명

메서드 Implicit 를 사용하면 컴파일러가 명시적 캐스팅 연산자(C#)나 변환 함수 호출(Visual Basic의 경우)없이 개체 DateTimeOffset 를 개체로 자동으로 변환 DateTime 할 수 있습니다. 데이터 손실을 포함하지 않고 을 throw하지 않는 확대 변환을 OverflowException정의합니다. 메서드는 Implicit 다음과 같은 코드를 가능하게 합니다.

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.
let timeWithOffset = DateTime(2008, 7, 3, 18, 45, 0)
printfn $"{timeWithOffset}"

let timeWithOffset = DateTime.UtcNow
printfn $"{timeWithOffset}"

let timeWithOffset =
    DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Unspecified)

printfn $"{timeWithOffset}"

let timeWithOffset =
    DateTime(2008, 7, 1, 2, 30, 0)
    + TimeSpan(1, 0, 0, 0)

printfn $"{timeWithOffset}"

let timeWithOffset = DateTime(2008, 1, 1, 2, 30, 0)
printfn $"{timeWithOffset}"

// 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 . 결과 DateTimeOffset 개체의 오프셋은 매개 변수의 DateTime.Kind 속성 dateTime 값에 따라 달라집니다.

이 연산자에 대 한 해당 메서드는 DateTimeOffset.DateTimeOffset(DateTime)

적용 대상