Analytics


Google

Saturday, April 10, 2010

Computing and Displaying elapsed time In Java program

To do that capture the start using a long variable as shown below and then compute it against the currentTimeMillis to display.

In the example below, I am displaying in Second.

public static void main(String[] args) {

        // Initialize some parameters
        long stTime = System.currentTimeMillis();
        System.out.println("Elapse time: " + ((System.currentTimeMillis() - stTime) / 1000));
        System.out.println("End Program");

    }

No comments: