Elapsed time since function last call
<p>I am trying to write a method that will return the amount of time that has passed since the method was last called, it looks like this:</p>

<pre><code>package JGame.Util;

import java.util.Date;

public class Util{

    protected static Long lastTime = null;

    public static long getLastTime(){
        long time = new Date().getTime();
        if(Util.lastTime == null){
            Util.lastTime = time;
            return 0;
        }
        long ftime = time - Util.lastTime;
        Util.lastTime = time;
        return ftime;
    }
}
</code></pre>

<p>I am then calling the method like this, within a key press event:</p>

<pre><code>long lastTime = Util.getLastTime();
if(lastTime &gt; 1000){
    return;
}
System.out.println(lastTime);
</code></pre>

<p>The problem I am having, is that when the key is pressed down it prints out <code>lastTime</code>, but it should only be printed out once every second.</p>

<p>here is the output:</p>

<pre><code>122
6
7
13
9
7
10
9
10
</code></pre>

<p>While holding down the key, I was expecting all to be very close to 1 second intervals. but the numbers are not even close.</p>
