Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , , , ,

Sponsored Links



Retrieving interval of time

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 23-02-2010
Member
 
Join Date: Dec 2009
Posts: 211
Retrieving interval of time

Hello,
I want to recover the amount of time doing in a particular program.
So I use this:
Code:
long tm = (new GregorianCalendar()).getTimeInMillis();
treatment ();
tm = (new GregorianCalendar()).getTimeInMillis() - Time;
Is there another less expensive method (without creating an object instance).
Reply With Quote
  #2  
Old 23-02-2010
Member
 
Join Date: Nov 2009
Posts: 583
Re: Retrieving interval of time

Hello,
You can try the following code:
Code:
long str = System.currentTimeInMillis();
treatment ();
System.out.System.out.println("Running Time:+(System.currentTimeInMillis()-str));
Hope this will help you. If you have any more problem then do post back.
Reply With Quote
  #3  
Old 23-02-2010
Member
 
Join Date: Nov 2009
Posts: 447
Re: Retrieving interval of time

Hello,
Check out the following code
Code:
/ / Get current time
    long str = System.currentTimeMillis();
    
    / / Do something ...
    
    / / Get time elapsed in milliseconds
    long elapsedTimeMillis = System.currentTimeMillis()-str;
    
    / / Get elapsed time in seconds
    float sts = elapsedTimeMillis/1000F;
    
    / / Get elapsed time in minutes
    float elapsedTimeMin = elapsedTimeMillis /(60* 1000F);
    
    / / Get elapsed time in hours
    float eth = elapsedTimeMillis /(60*60* 1000F);
    
    / / Get elapsed time in days
    float etd = elapsedTimeMillis /(24*60*60* 1000F);
Reply With Quote
  #4  
Old 23-02-2010
Member
 
Join Date: Nov 2009
Posts: 335
Re: Retrieving interval of time

Hello,
Why use GreporianCalendar is something quite compet me hungry and therefore memory, the simple class java.util.Date faisq quite the case:
Code:
long tm = (new Date()).getTime();
treatment ();
tm = (new Date()).getTime() - Time;
Otherwise what is more expensive between the call to a static method of class System and the creation of an object type Date (assuming that the manufacturer conducts date if the same treatment at least one treatment very close relative System.currentTime to class ...) The difference must be in thousandths of seconds, which is in any case very inexpensive. I therefore see no reason why you say that the treatment of GregorianCalendar is very expensive?
Reply With Quote
  #5  
Old 23-02-2010
Member
 
Join Date: Nov 2009
Posts: 333
Re: Retrieving interval of time

Hello,
I would like to the above post, of course, you want to have a processing time to the millionth of a second. In any case, the measure of processing time is useful for treatment rather expensive so a difference of a few thousandths of a second is negligible. If you need any more help regarding this topic then please do post back and do not forget to post your error with the code.
Reply With Quote
  #6  
Old 23-02-2010
Member
 
Join Date: Dec 2009
Posts: 211
Re: Retrieving interval of time

Hello,
Thanks for you reply. It works great so the problem is RESOLVED. So thank you again (mostly for speed)
The exact name of the method is:
Code:
long Time = System.currentTimeMillis();
Not:
Code:
System.currentTimeInMillis ()
If you guys know any other alternative for doing the same, then please do post back, it will help me a lot.
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Retrieving interval of time"
Thread Thread Starter Forum Replies Last Post
unable to finish the quest because Age of empires online disconnect at regular interval of time Leslie f Video Games 6 20-08-2011 01:11 AM
Airtel broadband connection keeps on getting disconnected at regular interval of time? Ashley Parker Technology & Internet 7 30-07-2011 01:24 AM
LG optimus 2x smart phone get stucked at regular interval of time? Bontu Portable Devices 4 07-07-2011 04:45 AM
How to modify time interval in movie maker of Windows XP Urvaksh Windows Software 4 04-01-2011 08:27 PM
Problem in retrieving timestamp Logan 2 Software Development 5 12-02-2010 01:55 AM


All times are GMT +5.5. The time now is 12:13 PM.