C# DateTimeOffset Year

Description

DateTimeOffset Year gets the year component of the date represented by the current DateTimeOffset object.

Syntax

DateTimeOffset.Year has the following syntax.


public int Year { get; }

Example

The following example displays the year component of a DateTimeOffset value in four different ways:


using System;//from www  .  j ava  2  s  . c  o m

public class MainClass{
  public static void Main(String[] argv){  
    DateTimeOffset theTime = new DateTimeOffset(2014, 2, 17, 9, 0, 0, 
                                 DateTimeOffset.Now.Offset);
    Console.WriteLine("The year component of {0} is {1}.", 
                      theTime, theTime.Year);
    
    Console.WriteLine("The year component of {0} is{1}.", 
                      theTime, theTime.ToString(" y"));
    
    Console.WriteLine("The year component of {0} is {1}.", 
                      theTime, theTime.ToString("yy"));
    
    Console.WriteLine("The year component of {0} is {1}.", 
                      theTime, theTime.ToString("yyyy"));

  }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version