Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Clocking  RSS feed

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I was wondering how would you see how long a program has been running? I've tried looking in the calendar class, but I cant seem to get it to work. Do you guys have any ideas?
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just start a new timer at the start of program execution with the statement:
long startTime = System.currentTimeMillis();
at the end of the program, get the current time by :
long endTime = System.currentTimeMillis();
you can then get the execution time in milliseconds which (im sorry, you have to manually convert into an appropriate format)
hope this helps
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!