public class Year
{
public static int DayOfYear(int year, int month, int day)
{
int i = 1;
int sumDay = day;
while (i < month)
{
if (i == 2)
{
if (IsBissextile(year))
{
sumDay += 28;
}
else
{
sumDay += 29;
}
//精简方法二:
//sumDay += IsBissextile(year) ? 28 : 29;
}
else
{
if (i <= 7)
{
sumDay += (i % 2 == 0 ? 30 : 31);
}
else
{
sumDay += (i % 2 == 0 ? 31 : 30);
}
}
++i;
}
return sumDay;
}
public static bool IsBissextile(int year)
{
if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))
{
return true;
}
return false;
}
public Year()
{
}
}
{
public static int DayOfYear(int year, int month, int day)
{
int i = 1;
int sumDay = day;
while (i < month)
{
if (i == 2)
{
if (IsBissextile(year))
{
sumDay += 28;
}
else
{
sumDay += 29;
}
//精简方法二:
//sumDay += IsBissextile(year) ? 28 : 29;
}
else
{
if (i <= 7)
{
sumDay += (i % 2 == 0 ? 30 : 31);
}
else
{
sumDay += (i % 2 == 0 ? 31 : 30);
}
}
++i;
}
return sumDay;
}
public static bool IsBissextile(int year)
{
if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))
{
return true;
}
return false;
}
public Year()
{
}
}