Home »
C#
C# | DateTime.Year Property with Example
DateTime.Month Property: Here, we are going to learn about the Month Property of DateTime class with example in C#.
By IncludeHelp Last updated : August 27, 2023
C# DateTime.Month Property
DateTime.Month Property is used to get the year component of this object. It's a GET property of DateTime class.
Syntax
int DateTime.Year;
Parameter(s)
- It does not accept any parameter.
Return value
The return type of this Property is int, it returns an integer value i.e the year component of this object.
Example to demonstrate 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/24/2019 8:08:55 AM
Year is : 2019