DateTimeOffset.Hour Eigenschap

Definitie

Hiermee wordt het uurgedeelte van de tijd opgehaald dat wordt vertegenwoordigd door het huidige DateTimeOffset object.

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

Waarde van eigenschap

Het uurgedeelte van het huidige DateTimeOffset object. Deze eigenschap maakt gebruik van een 24-uurs klok; de waarde varieert van 0 tot 23.

Voorbeelden

In het volgende voorbeeld wordt het uuronderdeel van een DateTimeOffset object op drie verschillende manieren weergegeven:

  • Door de waarde van de Hour eigenschap op te halen.

  • Door de ToString(String) methode aan te roepen met de notatieaanduiding H.

  • Door de ToString(String) methode aan te roepen met de notatieaanduiding HH.

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.

Opmerkingen

De Hour eigenschap wordt niet beïnvloed door de waarde van de Offset eigenschap.

U kunt ook een tekenreeksweergave van het uuronderdeel van een DateTimeOffset object maken door de ToString methode aan te roepen met de aangepaste notatieaanduidingen H of UU.

Van toepassing op