-8

I already start programming a code that download a file using Java but , I want to calculate the total time of downloading

I search but I only found it using system.currenttimemillis()
but the output will be like this http://tinypic.com/r/2mgkt5k/5

I want to print output that can tell total time(in milli second)

Reema_
  • 1
  • 3

2 Answers2

0

try this http://introcs.cs.princeton.edu/java/stdlib/Stopwatch.java.html

that's very easy

Stopwatch st = new Stopwatch();

// Do something. In your case Upload image !

double time = st.elapsedTime(); // the result in millis

// Print time 

This class is a part of stdlib.jar

Mohsin Husen
  • 1,008
  • 10
  • 17
  • it's the same ! this is the output http://tinypic.com/r/23vysl5/5 i want the output to be like this http://tinypic.com/r/nyv7ue/5 one line only not more :( – Reema_ Oct 10 '13 at 10:59
0

Something like the below may be feasible here:

long a = System.nanoTime();

//Do your stuff

System.out.println("Total time taken: " + System.nanoTime() - a);
Levenal
  • 3,796
  • 3
  • 24
  • 29
  • it's the same ! this is the output http://tinypic.com/r/23vysl5/5 i want the output to be like this http://tinypic.com/r/nyv7ue/5 one line only not more :( – Reema_ Oct 10 '13 at 10:58
  • My answer should give you the nanoseconds the process took, have a look at this http://stackoverflow.com/questions/924208/how-to-convert-nanoseconds-to-seconds-using-the-timeunit-enum also which may help you convert it into seconds – Levenal Oct 10 '13 at 11:08