//Gives back the number of days that have passed since the begining of a year.
//1-365.
public static int dayOfYear(String date) {
int[] daysInMonth = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
String[] dateArr = date.trim().split("-");
int year = Integer.parseInt(dateArr[0]);
int month = Integer.parseInt(dateArr[1]);
int day = Integer.parseInt(dateArr[2]);
if(leapYear(year)) daysInMonth[1] = 29;
int total = 0;
for(int i = 0; i < month; i++){
total += daysInMonth[i];
}
total+=day;
return total;
}
public static boolean leapYear(int year){
boolean leap = false;
if(year % 4 == 0)
{
if( year % 100 == 0)
{
// year is divisible by 400, hence the year is a leap year
if ( year % 400 == 0)
leap = true;
else
leap = false;
}
else
leap = true;
}
else
leap = false;
if(leap)
return true;
else
return false;
}