Hi I've tried to substract hour from a Date using Date.getTime() - (time in ms ) but the result is not correct , there is always a slight gap compared to the good result, any idea ?
if(hoursToBeSubstracted<1) {
float toMinute = hoursToBeSubstracted*60;
return new Date((long)(d1.getTime()-toMinute*60000));
}
return new Date((long)(d1.getTime() - 3600 * hoursToBeSubstracted * 1000));
Example of output :
Before operation Thu Dec 01 13:27:30 CET 2022
Substracting 60.0 minutes
After operation Thu Dec 01 12:28:31 CET 2022
Before operation Wed Nov 30 16:48:52 CET 2022
Substracting 60.0 minutes
After operation Wed Nov 30 15:49:53 CET 2022
Before operation Wed Nov 30 16:48:52 CET 2022
Substracting 60.0 minutes
After operation Wed Nov 30 15:49:53 CET 2022
Before operation Wed Nov 30 16:48:52 CET 2022
Substracting 60.0 minutes
After operation Wed Nov 30 15:49:53 CET 2022
Before operation Thu Dec 01 13:27:30 CET 2022
Substracting 60.0 minutes
After operation Thu Dec 01 12:28:31 CET 2022