DateTimeOffset.Hour Propiedad

Definición

Obtiene el componente de hora de la hora representada por el objeto DateTimeOffset actual.

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

Valor de propiedad

Componente de hora del objeto DateTimeOffset actual. Esta propiedad usa un reloj de 24 horas; el valor va de 0 a 23.

Ejemplos

En el ejemplo siguiente se muestra el componente de hora de un DateTimeOffset objeto de tres maneras diferentes:

  • Recuperando el valor de la Hour propiedad .

  • Llamando al ToString(String) método con el especificador de formato "H".

  • Llamando al ToString(String) método con el especificador de formato "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.

Comentarios

La Hour propiedad no se ve afectada por el valor de la Offset propiedad .

También puede crear una representación de cadena del componente de hora de un DateTimeOffset objeto llamando al ToString método con los especificadores de formato personalizado "H" o "HH".

Se aplica a