0

I can't figure out at the moment how am I going to calculate the total hours worked of an employee. Example:

Time-in: 07:00
Time-out: 05:00

I have two JTextField, that's where the user will input. How am I going to do it when he clicks my JButton Calculate Hours? Sorry guys, I know this is pretty easy but I am completely a novice, please help!

Ciara
  • 197
  • 1
  • 3
  • 11
  • 1
    Please let us know what have you tried ? – Apurv Feb 19 '13 at 11:57
  • 2
    I'd say, in the example he worked -2 hours. Can they stay more than one entire day? Which format does the Time have? – Burkhard Feb 19 '13 at 11:58
  • Very similar: http://stackoverflow.com/questions/3526485/how-do-you-subtract-dates-in-java – slim Feb 19 '13 at 12:05
  • Oh yeah right. I was thinking a 24-hour format... But what if he inputs a wrong time? How do I do exception handling? – Ciara Feb 19 '13 at 12:10

1 Answers1

1

First, you must convert the input into two Date or Calendars.

Then check Calculating difference in dates in Java

Community
  • 1
  • 1
Sporniket
  • 339
  • 1
  • 4