DateTimeOffset.DateTime 属性
定义
获取 DateTime 值,该值表示当前 DateTimeOffset 对象的日期和时间。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
属性值
当前 DateTimeOffset 对象的日期和时间。The date and time of the current DateTimeOffset object.
示例
下面的示例演示 DateTime 如何使用属性将和属性返回的时间转换 Now UtcNow 为 DateTime 值。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.
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 。The DateTime property is not affected by the value of the Offset property.
此属性返回对象的日期和时间部分 DateTimeOffset ,这使它对于执行转换很有用 DateTimeOffset DateTime 。This property returns both the date and the time component of a DateTimeOffset object, which makes it useful for performing DateTimeOffset to DateTime conversion. 例如,如果对象的 DateTimeOffset 日期和时间值为 "1/12/07 4: 01pm + 7:30",则该属性返回日期 "1/12/07 4: 01pm"。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".
DateTime.Kind返回的对象的属性值 DateTime 为 DateTimeKind.Unspecified 。The value of the DateTime.Kind property of the returned DateTime object is DateTimeKind.Unspecified.