Mögliche Duplizieren:
Calculating the Difference Between Two Java Date InstancesWie bekomme ich die Anzahl der Tage zwischen zwei Daten in Java?
Wie erhalte ich Anzahl der Tage zwischen zwei Daten in Java?
Was ist der beste Weg? Hier ist, was ich habe, aber es ist nicht das beste:
public static ConcurrentHashMap<String, String> getWorkingDaysMap(int year,
int month, int day){
int totalworkingdays=0,noofdays=0;
String nameofday = "";
ConcurrentHashMap<String,String> workingDaysMap =
new ConcurrentHashMap<String,String>();
Map<String,String> holyDayMap = new LinkedHashMap<String,String>();
noofdays = findNoOfDays(year,month,day);
for (int i = 1; i <= noofdays; i++) {
Date date = (new GregorianCalendar(year,month - 1, i)).getTime();
// year,month,day
SimpleDateFormat f = new SimpleDateFormat("EEEE");
nameofday = f.format(date);
String daystr="";
String monthstr="";
if(i<10)daystr="0";
if(month<10)monthstr="0";
String formatedDate = daystr+i+"/"+monthstr+month+"/"+year;
if(!(nameofday.equals("Saturday") || nameofday.equals("Sunday"))){
workingDaysMap.put(formatedDate,formatedDate);
totalworkingdays++;
}
}
return workingDaysMap;
}
public static int findNoOfDays(int year, int month, int day) {
Calendar calendar = Calendar.getInstance();
calendar.set(year, month - 1, day);
int days = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
return days;
}
Insbesondere diese Antwort: http://StackOverflow.com/a/4549327/22656 –