I use some kind of stopwatch in my project and I have
start time ex: 18:40:10 h
stop time ex: 19:05:15 h
I need a result from those two values like final time = stop - start
I found some examples but they all are very confusing .
Is there any simple solution ?
Try this answer it will help you a lot
from here
In this answer, you will find subtract to two times discarding the day and month and year.
it gives you the number of minutes you will spend until you reach the second Time value.
If you have strings you need to parse them into a java.util.Date using java.text.SimpleDateFormat. Something like:
Here diff is the number of milliseconds elapsed between 18:40:10 and 19:05:15.
EDIT 1:
Found a method online for this (at http://www.javaworld.com/javaworld/jw-03-2001/jw-0330-time.html?page=2):
EDIT 2:
If you want it as a string (this is a sloppy way, but it works):
EDIT 3:
If you want the milliseconds just do this
You can then divide that by 1000 to get the fractional part of your seconds.
Assuming you are using java.util.Date:
The result will be the total time in milliseconds.