DateTimeOffset.Hour プロパティ

定義

現在の DateTimeOffset オブジェクトが表す時刻の時間要素を取得します。

public:
 property int Hour { int get(); };
public int Hour { get; }
member this.Hour : int
Public ReadOnly Property Hour As Integer

プロパティ値

Int32

現在の DateTimeOffset オブジェクトの時間要素。 このプロパティには、0 ~ 23 の値の範囲をとる 24 時間制が使用されます。

次の例では、オブジェクトの時間コンポーネントを DateTimeOffset 3 つの異なる方法で表示します。

  • プロパティの 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.

注釈

このプロパティは Hour 、プロパティの値の影響を Offset 受けません。

また、"H" または "HH" カスタム書式指定子を使用してメソッドをToString呼び出すことで、オブジェクトの時間コンポーネントの文字列表現DateTimeOffsetを作成することもできます。

適用対象