Pages

Sunday, September 15, 2013

Check Leap year-C#

We can use IsLeapYear function, it returns Bool value i.e True or False value.

If the Year is a leap year, it returns "True" otherwise "False".


DateTime dt = Convert.ToDateTime(DateTime.Now);

System.Globalization.Calendar myCal = CultureInfo.InvariantCulture.Calendar;

int _year=2012;

Response.Write("For"+_year+", Leap Year Result: " + myCal.IsLeapYear(_year));

_year=2013;

Response.Write("For"+_year+", Leap Year Result: " + myCal.IsLeapYear(_year));


OUTPUT:

For 2012, Leap Year Result: True
For 2013, Leap Year Result: False

No comments:

Post a Comment