DateTimeOffset.DateTime 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取 DateTime 值,该值表示当前 DateTimeOffset 对象的日期和时间。
public:
property DateTime DateTime { DateTime get(); };
public DateTime DateTime { get; }
member this.DateTime : DateTime
Public ReadOnly Property DateTime As DateTime
属性值
当前 DateTimeOffset 对象的日期和时间。
示例
下面的示例演示了使用 DateTime 属性将属性返回 Now 的时间和 UtcNow 属性转换为 DateTime 值。
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.
注解
该 DateTime 属性不受该属性的值 Offset 的影响。
此属性返回对象的日期和时间组件 DateTimeOffset ,这使得它可用于执行 DateTimeOffset 到 DateTime 转换。 例如,如果 DateTimeOffset 对象具有日期和时间值“1/12/07 4:01pm + 7:30”,则属性返回日期“1/12/07 4:01pm”。
DateTime.Kind返回DateTime对象的属性值为 DateTimeKind.Unspecified.