Question about Time

Started by Grilled, March 30, 2015, 14:05:50

Previous topic - Next topic

Grilled

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...?

SHC

I simply add elapsed time to a variable to achieve this.

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.