We have IsLeapYear DateTime in-built function or method which returns True if Year is a Leap year otherwise returns False.
For Example:- public bool IsLeapYear(DateTime GivenDate)
{
if(DateTime.IsLeapYear(GivenDate.Year))
{
return true;
}
return false;
}
To check above function:-
if (IsLeapYear(DateTime.Now))
Response.Write(DateTime.Now.Year + " Is a Leap Year" + "<br/>");
else
Response.Write(DateTime.Now.Year + " Is not a Leap Year" + "<br/>");
if (IsLeapYear(DateTime.Now.AddYears(1)))
Response.Write(DateTime.Now.AddYears(1).Year + " Is a Leap Year" + "<br/>");
else
Response.Write(DateTime.Now.AddYears(1).Year + " Is not a Leap Year" + "<br/>");
Output:-
2015 Is not a Leap Year
2016 Is a Leap Year because year divided by 4.