DateTimeOffset.Hour Vlastnost
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Získá hodinovou komponentu času reprezentované aktuálním DateTimeOffset objektem.
public:
property int Hour { int get(); };
public int Hour { get; }
member this.Hour : int
Public ReadOnly Property Hour As Integer
Hodnota vlastnosti
Hodinová komponenta aktuálního DateTimeOffset objektu. Tato vlastnost používá 24hodinový formát; rozsah hodnot je od 0 do 23.
Příklady
Následující příklad zobrazuje hodinovou komponentu objektu DateTimeOffset třemi různými způsoby:
Načtením hodnoty vlastnosti Hour.
ToString(String) Voláním metody se specifikátorem formátu "H".
ToString(String) Voláním metody se specifikátorem formátu "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.
Poznámky
Vlastnost Hour není ovlivněna hodnotou Offset vlastnosti.
Můžete také vytvořit řetězcovou reprezentaci DateTimeOffset hodinové komponenty objektu voláním ToString metody pomocí specifikátorů vlastního formátu "H" nebo "HH".