Hello Guest

Question about Time

  • 1 Replies
  • 3362 Views
Question about Time
« on: March 30, 2015, 14:05:50 »
Quick question. Printing System.getTimeMillis()/1000 results in the time in seconds from January 1, 1999- or something like that right? Please correct me if I'm wrong. How would you reset this to display time in seconds starting at 0,1,2,3...?

*

Offline SHC

  • **
  • 94
    • GoHarsha.com
Re: Question about Time
« Reply #1 on: March 30, 2015, 14:46:22 »
I simply add elapsed time to a variable to achieve this.

Code: [Select]
long start = getCurrentTime(); // This is your method that returns time in seconds
long now  = start;
long elapsed;

while (running)
{
    now = getCurrentTime();
    elapsed = now - start;

    System.out.println(elapsed);
}

This example prints out the number of seconds starting from 0.