Categories
Asp, Asp.net

How To Check Leap Year In Asp.Net

How To Check Leap Year In Asp.Net

In this post i am going to explain that how to check that current year is Leap or not in Asp.Net.It is very simple and having just a few lines of code.

Method 1:-

protected void Page_Load(object sender, EventArgs e)
        {
            Int32 Year = DateTime.Now.Year;

            if (DateTime.IsLeapYear(Year))
            {
                Response.Write("This is a Leap year");
            }
            else
            {
                Response.Write("This is Not a leap year");
            }

        }

Method 2:-

function leap()
{
 var yr=document.getElementById("year").value;
 if ((parseInt(yr)%4) == 0)
 {
  if (parseInt(yr)%100 == 0)
  {
    if (parseInt(yr)%400 != 0)
    {
    alert("Year is Not Leap");
    return "false";
    }
    if (parseInt(yr)%400 == 0)
    {
    alert("This year is Leap");
    return "true";
    }
  }
  if (parseInt(yr)%100 != 0)
  {
    alert("This year is Leap");
    return "true";
  }
 }
 if ((parseInt(yr)%4) != 0)
 {
    alert("This is Not Leap");
    return "false";
 } 
}

Method 3:-

            int year = 2400;
            if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
            {
                Response.Write("This is a Leap Year");

            }
            else
            {
                Response.Write("This is Not a Leap Year");
            }