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。