0

I am calculating time between two given dates. And I am also saving the lunch time that can be anything from 1 hour and 45 minutes or more. The lunch time I am saving the hours in one variable and the minutes in another.

Let's say that my worked time is 11 hours and 0 minutes and my lunch break is 1 hour and 45 minutes. How do I subtract this from my worked time that 11 hour so I get 9 hours and 15 minutes in this case.

codemoonger
  • 613
  • 3
  • 11
  • 22
  • http://stackoverflow.com/questions/4927856/how-to-calculate-time-difference-in-java this may be help ful – Manohar Jun 28 '16 at 10:32

1 Answers1

-1

Try this :

int workTimeHours = 11;
int workTimeMinutes = 0;
int workTimeSecs = 10;
int time1 =  workTimeHours*3600 + workTimeMinutes*60+ workTimeSecs;

int breakTimeHours = 1;
int breakTimeMinutes = 45;
int breakTimeSecs = 11;
int time2 = breakTimeHours*3600 + breakTimeMinutes*60+ breakTimeSecs;

int timeDiff = time1 - time2;

This will give you the time difference(timeDiff) which is in seconds from which you can get your hours, minutes and secs!

Ashish Ranjan
  • 5,523
  • 2
  • 18
  • 39