• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

calculate time difference b/w two time entry

 
Shweta Chakraborty
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello
Sir

Please help me I m developing screen for login where I mentioned to give login time in AM and PM.I m using spinner to enter time and calculating the time but there is some problem.
I m using simpleDateFormat class constructor("HH:mm:ss") but not getting d difference.

Please help me to get time difference b/w two time inputs like 10.05AM and 8.05PM.


cheers,
Shweta Chakraborty
 
Maneesh Godbole
Saloon Keeper
Posts: 11096
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

In pseudo code
1) Obtain the Date object for the two time inputs (Check the Simple/DateFormat class for methods which will parse the string format and provide you a date object)
2) Obtain the time long value
3) Compute timeValue1-timeValue2 to obtain the difference. Result will indicate long milliseconds
4) Divide result to obtain seconds,minutes,hours

Hint:
Milliseconds=1000 seconds
60 seconds=minute
60 minutes= hour
 
Campbell Ritchie
Sheriff
Pie
Posts: 49793
69
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might be able to use the TimeUnit enum to help with the difference between hours and seconds.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic