DateTimeOffset.Hour 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取由当前 DateTimeOffset 对象所表示的时间的小时组成部分。
public:
property int Hour { int get(); };
public int Hour { get; }
member this.Hour : int
Public ReadOnly Property Hour As Integer
属性值
当前 DateTimeOffset 对象的小时组成部分。 此属性使用 24 小时制;值介于 0 到 23 之间。
示例
以下示例以三种不同的方式显示对象的小时组件 DateTimeOffset :
通过检索属性的值 Hour 。
通过使用“H”格式说明符调用 ToString(String) 方法。
通过使用“HH”格式说明符调用 ToString(String) 方法。
DateTimeOffset theTime = new DateTimeOffset(2008, 3, 1, 14, 15, 00,
DateTimeOffset.Now.Offset);
Console.WriteLine("The hour component of {0} is {1}.",
theTime, theTime.Hour);
Console.WriteLine("The hour component of {0} is{1}.",
theTime, theTime.ToString(" H"));
Console.WriteLine("The hour component of {0} is {1}.",
theTime, theTime.ToString("HH"));
// The example produces the following output:
// The hour component of 3/1/2008 2:15:00 PM -08:00 is 14.
// The hour component of 3/1/2008 2:15:00 PM -08:00 is 14.
// The hour component of 3/1/2008 2:15:00 PM -08:00 is 14.
let theTime = DateTimeOffset(2008, 3, 1, 14, 15, 00, DateTimeOffset.Now.Offset)
printfn $"The hour component of {theTime} is {theTime.Hour}."
printfn $"""The hour component of {theTime} is{theTime.ToString " H"}."""
printfn $"The hour component of {theTime} is {theTime:HH}."
// The example produces the following output:
// The hour component of 3/1/2008 2:15:00 PM -08:00 is 14.
// The hour component of 3/1/2008 2:15:00 PM -08:00 is 14.
// The hour component of 3/1/2008 2:15:00 PM -08:00 is 14.
Dim theTime As New DateTimeOffset(#3/1/2008 2:15PM#, _
DateTimeOffset.Now.Offset)
Console.WriteLine("The hour component of {0} is {1}.", _
theTime, theTime.Hour)
Console.WriteLine("The hour component of {0} is{1}.", _
theTime, theTime.ToString(" H"))
Console.WriteLine("The hour component of {0} is {1}.", _
theTime, theTime.ToString("HH"))
' The example produces the following output:
' The hour component of 3/1/2008 2:15:00 PM -08:00 is 14.
' The hour component of 3/1/2008 2:15:00 PM -08:00 is 14.
' The hour component of 3/1/2008 2:15:00 PM -08:00 is 14.
注解
还可以通过使用“H”或“HH”自定义格式说明符调用ToString方法来创建对象的小时组件的字符串表示形式DateTimeOffset。