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 개체의 시 구성 요소입니다. 이 속성에는 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.

설명

속성 값 HourOffset 영향을 받지 않습니다.

"H" 또는 "HH" 사용자 지정 형식 지정자를 사용하여 메서드를 호출 ToString 하여 개체의 시간 구성 요소에 대한 문자열 표현 DateTimeOffset 을 만들 수도 있습니다.

적용 대상