C# DateTime.Year Property with Example

C# DateTime.Year Property with Example

Syntax

int DateTime.Year;

Example to demonstrate an example of DateTime.Month Property

using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            //creating an object of DateTime class
            //and, initializing it with the current time 
            //using "Now"           
            DateTime dt = DateTime.Now;

            //getting year component 
            string month = dt.Year.ToString();

            //printing current date & time 
            Console.WriteLine("Current date & time is: " + dt.ToString());
            //printing the day of the week
            Console.WriteLine("Year is : " + month);

            //just to print a new line
            Console.WriteLine();
        }
    }
}

Output-

Current date & time is: 10/25/2019 8:08:55 AM
Year is : 2019

Recent Posts

error: Alert: Content is protected!!