java输入日期,格式为"YYYY-MM-DD",判断这天是一年中的第几天
public class DayOfYear {
public static int dayOfYear(String str){
int[] monthNum = {31,28,31,30,31,30,31,31,30,31,30,31};
int dayCount=0;
String[] date = str.split("-");
int year = Integer.parseInt(date[0]);
int month = Integer.parseInt(date[1]);
int day = Integer.parseInt(date[2]);
if(year%4==0){
monthNum[1]+=1;
}
for(int i=0;i<month-1;i++){
dayCount+=monthNum[i];
}
return dayCount+day;
}
}