Get the hour component of the time represented by the current DateTimeOffset object in CSharp

Description

The following code shows how to get the hour component of the time represented by the current DateTimeOffset object.

Example


using System;//from  ww w  . ja v  a 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.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var