Check whether Year is a Leap Year or Not?

Posted by Vishalneeraj-24503 under Visual Studio category on | Points: 40 | Views : 299
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)
return true;
return false;

To check above function:-
if (IsLeapYear(DateTime.Now))
Response.Write(DateTime.Now.Year + " Is a Leap Year" + "<br/>");
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/>");
Response.Write(DateTime.Now.AddYears(1).Year + " Is not a Leap Year" + "<br/>");

2015 Is not a Leap Year
2016 Is a Leap Year because year divided by 4.

Comments or Responses

Login to post response