Get the number of days in a given year - CSharp System

CSharp examples for System:DateTime

Description

Get the number of days in a given year

Demo Code


using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;//w w w .  ja va2s  .  c  o  m

public class Main{
        /// <summary>
        /// Get the number of days in a given year
        /// </summary>
        /// <param name="year"></param>
        /// <returns></returns>
        public static int GetDaysInYear(int year)
        {
            if (year % 4 != 0)
                return 365;

            if (year % 100 == 0 && year % 400 != 0)
                return 365;
            else
                return 366;
        }
}

Related Tutorials