C# DateTimeOffset Hour
Description
DateTimeOffset Hour
gets the hour component of the time
represented by the current DateTimeOffset object.
Syntax
DateTimeOffset.Hour
has the following syntax.
public int Hour { get; }
Example
The following example displays the hour component of a DateTimeOffset object in three different ways:
using System;//from w w w .ja va 2 s . c o m
public class MainClass{
public static void Main(String[] argv){
DateTimeOffset theTime = new DateTimeOffset(2014, 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 code above generates the following result.