Hack Forums
[Java] Subtracting time in java. - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Java] Subtracting time in java. (/showthread.php?tid=5064723)



Subtracting time in java. - Cork - Nov 20, 2015

Doing an assignment in college which requires me to read in a start time and end time and then substract in order to get the duration time. I'm only a beginner so any help would be great.


* - Mouse❤️ - Nov 20, 2015

http://lmgtfy.com/?q=java+time+duration

Help? First lesson: Google knows more than the people you're asking for help.


* - MrOrang - Nov 20, 2015

This is really basic. Have a look at the code below. It gives you the duration in milliseconds:

Code
long start = System.currentTimeMillis();
//do your stuff
long end = System.currentTimeMillis();

long duration = end - start;



* - sfdemo - Nov 20, 2015

1)read both the start and end time
2) convert them to epoch format
3) subtract them
4) divide to get the duration


* - knrd - Nov 21, 2015

get your start time and subtract it from your endtime?


* - rusia - Nov 22, 2015

lmbo just ur turn clock backwards xd