Date time Value from DateTimeOffset

In this chapter you will learn:

  1. Gets hour from DateTimeOffset
  2. Gets year from DateTimeOffset

Gets hour from DateTimeOffset

using System;//from  j  a  v  a  2s . c o m
using System.Globalization;
public class Test
{
   public static void Main()
   {
        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"));
        Console.WriteLine("The second component of {0} is {1}.", theTime, theTime.Second);        
   }
}

Gets year from DateTimeOffset

using System;//from j ava 2  s. co m
using System.Globalization;

public class Example
{
   public static void Main()
   {
        DateTimeOffset theTime = new DateTimeOffset(2008, 2, 17, 9, 0, 0, DateTimeOffset.Now.Offset);
        Console.WriteLine("The year component of {0} is {1}.", theTime, theTime.Year);
        
   }
}

Next chapter...

What you will learn in the next chapter:

  1. Use the Compare() method to compare DateTime instances
  2. Use the overloaded less than operator (<) to compare two DateTime instances
  3. Use the Equals() method to compare DateTime instances
Home » C# Tutorial » Date, Time, TimeZone
Compare DateTimeOffset
DateTimeOffset creation
Date time Value from DateTimeOffset
Compare DateTime value
DateTime constant value
DateTime constructor
DateTime properties
Create TimeSpan From
TimeSpan
TimeSpan add and subtract
DateTime and TimeSpan
Compare TimeSpan
TimeSpan constant
TimeSpan Constructor
TimeSpan Duration
TimeSpan format
Negate a TimeSpan
TimeSpan operators
Parse string to TimeSpan
TimeSpan to string
TimeSpan total properties
TimeSpan propeties
Daylight saving
Time zone ID
UTC offset with TimeZone
TimeZone converting
TimeZone creation