G
gdfgfd
Gast
Ich moechte die TAGESdifferenz zwischen zwei GregorianCalendar Objekten berechnen, wie geht das?
GregorianCalendar start = new GregorianCalendar();
GregorianCalendar ende = new GregorianCalendar();
start.setTime(Startzeit);
ende.setTime(Endzeit);
long diff = ((ende.getTimeInMillis()-start.getTimeInMillis()) / 1000) / 60;
public long getRemainingDays ( ) {
// Returns the time between now and the appointment in days
GregorianCalendar gcNow = new GregorianCalendar();
gcNow.set(Calendar.HOUR_OF_DAY, 0);
gcNow.set(Calendar.MINUTE, 0);
gcNow.set(Calendar.SECOND, 0);
gcNow.set(Calendar.MILLISECOND, 0);
GregorianCalendar gcAppointment = new GregorianCalendar(getYear(), getMonth() - 1, getDay());
// Datum hat schon alle Zeitlichen Angaben auf 0
// gcAppointment.set(Calendar.HOUR_OF_DAY, 0);
// gcAppointment.set(Calendar.MINUTE, 0);
// gcAppointment.set(Calendar.SECOND, 0);
// gcAppointment.set(Calendar.MILLISECOND, 0);
double dobDifference = ((double) (gcAppointment.getTimeInMillis() - gcNow.getTimeInMillis())) / 24 / 60 / 60 / 1000;
System.out.println(dobDifference);
return (long) dobDifference;
}
public long getRemainingDays ( ) {
// Returns the time between now and the appointment in days
GregorianCalendar gcNow = new GregorianCalendar();
gcNow.set(Calendar.HOUR_OF_DAY, 0);
gcNow.set(Calendar.MINUTE, 0);
gcNow.set(Calendar.SECOND, 0);
gcNow.set(Calendar.MILLISECOND, 0);
GregorianCalendar gcAppointment = new GregorianCalendar(getYear(), getMonth() - 1, getDay());
// Datum hat schon alle Zeitlichen Angaben auf 0
// gcAppointment.set(Calendar.HOUR_OF_DAY, 0);
// gcAppointment.set(Calendar.MINUTE, 0);
// gcAppointment.set(Calendar.SECOND, 0);
// gcAppointment.set(Calendar.MILLISECOND, 0);
return Math.round(((double) (gcAppointment.getTimeInMillis() - gcNow.getTimeInMillis())) / 24 / 60 / 60 / 1000);
}