DateTimeOffset.DateTime Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets a DateTime value that represents the date and time of the current DateTimeOffset object.
public:
property DateTime DateTime { DateTime get(); };
public DateTime DateTime { get; }
member this.DateTime : DateTime
Public ReadOnly Property DateTime As DateTime
Property Value
The date and time of the current DateTimeOffset object.
Examples
The following example illustrates the use of the DateTime property to convert the time returned by the Now and UtcNow properties to DateTime values.
DateTimeOffset offsetDate;
DateTime regularDate;
offsetDate = DateTimeOffset.Now;
regularDate = offsetDate.DateTime;
Console.WriteLine("{0} converts to {1}, Kind {2}.",
offsetDate.ToString(),
regularDate,
regularDate.Kind);
offsetDate = DateTimeOffset.UtcNow;
regularDate = offsetDate.DateTime;
Console.WriteLine("{0} converts to {1}, Kind {2}.",
offsetDate.ToString(),
regularDate,
regularDate.Kind);
// If run on 3/6/2007 at 17:11, produces the following output:
//
// 3/6/2007 5:11:22 PM -08:00 converts to 3/6/2007 5:11:22 PM, Kind Unspecified.
// 3/7/2007 1:11:22 AM +00:00 converts to 3/7/2007 1:11:22 AM, Kind Unspecified.
let offsetDate = DateTimeOffset.Now
let regularDate = offsetDate.DateTime
printfn $"{offsetDate} converts to {regularDate}, Kind {regularDate.Kind}."
let offsetDate = DateTimeOffset.UtcNow
let regularDate = offsetDate.DateTime
printfn $"{offsetDate} converts to {regularDate}, Kind {regularDate.Kind}."
// If run on 3/6/2007 at 17:11, produces the following output:
//
// 3/6/2007 5:11:22 PM -08:00 converts to 3/6/2007 5:11:22 PM, Kind Unspecified.
// 3/7/2007 1:11:22 AM +00:00 converts to 3/7/2007 1:11:22 AM, Kind Unspecified.
Dim offsetDate As DateTimeOffset
Dim regularDate As Date
offsetDate = DateTimeOffset.Now
regularDate = offsetDate.DateTime
Console.WriteLine("{0} converts to {1}, Kind {2}.", _
offsetDate.ToString(), _
regularDate, _
regularDate.Kind)
offsetDate = DateTimeOffset.UtcNow
regularDate = offsetDate.DateTime
Console.WriteLine("{0} converts to {1}, Kind {2}.", _
offsetDate.ToString(), _
regularDate, _
regularDate.Kind)
' If run on 3/6/2007 at 17:11, produces the following output:
'
' 3/6/2007 5:11:22 PM -08:00 converts to 3/6/2007 5:11:22 PM, Kind Unspecified.
' 3/7/2007 1:11:22 AM +00:00 converts to 3/7/2007 1:11:22 AM, Kind Unspecified.
Remarks
The DateTime property is not affected by the value of the Offset property.
This property returns both the date and the time component of a DateTimeOffset object, which makes it useful for performing DateTimeOffset to DateTime conversion. For example, if the DateTimeOffset object has a date and time value of "1/12/07 4:01pm + 7:30", the property returns a date of "1/12/07 4:01pm".
The value of the DateTime.Kind property of the returned DateTime object is DateTimeKind.Unspecified.
Applies to
See also
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기