after testing for hours and looking through the internet, I haven't found help for my problem...
Ok to my problem: I have two JSpinner, that show the current Hour and Minutes. They look like that:
Date date = new Date();
SpinnerDateModel sm = new SpinnerDateModel(date, null, null, Calendar.HOUR_OF_DAY);
TimeBeginSpinner = new javax.swing.JSpinner(sm);
JSpinner.DateEditor de = new JSpinner.DateEditor(TimeBeginSpinner, "HH:mm");
TimeBeginSpinner.setEditor(de);
Now to my question. I am trying to calculate the difference between these two time periods. But that does not always seem to work.
I tried two different versions, without an external lib and with JodaTime.
Without lib, i calculate it like that:
long diff = dateEnd.getTime() - dateBegin.getTime();
long diffMinutes = diff / (60 * 1000) % 60;
long diffHours = 24 + diff / (60 * 60 * 1000) % 24;
long diffDays = diff / (24 * 60 * 60 * 1000) + 16753;
dateEnd and dateBegin are the Dates i received from the JSpinner.
With JodaTime, i tried it like this:
Duration duration = new Duration(dateBegin.getTime(), dateEnd.getTime());
System.out.println("JodaTime Days: " + duration.getStandardDays());
System.out.println("JodaTime Hours: " + duration.getStandardHours());
System.out.println("JodaTime Minutes: " + duration.getStandardMinutes());
Now here comes the problem: If I calculate the difference without touching the JSpinner, it seems to work. Here my log:
JodaTime Days: 0
JodaTime Hours: 0
JodaTime Minutes: 0
calcTimeDiff: ---------------------------
getTime Begin: 1447617955831
getTime End: 1447617955831
diffDays: 0
diffHours: 0
diffMinutes: 0
Once I touch the second JSpinner and want to check if it calculates 1 hour difference correctly, something goes wrong... Here my log: JSpinner1 is still untouched, JSpinner2 is set one hour later.
JodaTime Days: -16753
JodaTime Hours: -402095
JodaTime Minutes: -24125700
calcTimeDiff: ---------------------------
getTime Begin: 1447617955831
getTime End: 75900000
diffDays: -16753
diffHours: 1
diffMinutes: 0
Turning JSpinner1 down 1 hour, should make a difference of 2 hours.
Log:
JodaTime Days: 0
JodaTime Hours: 2
JodaTime Minutes: 120
calcTimeDiff: ---------------------------
getTime Begin: 69060000
getTime End: 76260000
diffDays: 0
diffHours: 26
diffMinutes: 0
Does anyone know what goes wrong here?
Thanks for every help!