Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
6914 dpurdie 1
package com.erggroup.buildtool.utilities;
2
 
3
import java.text.SimpleDateFormat;
4
import java.util.Calendar;
5
 
6
public class ElapseTime {
7
 
8
    /** Capture the current time when the class is instantiated
9
     * 
10
     */
11
    long startTime;
12
 
13
    public ElapseTime()
14
    {
15
        reset();
16
    }
17
 
18
    public void reset()
19
    {
20
        startTime = System.nanoTime();
21
    }
22
 
23
    /**
24
     * Returns elapsed time as a string
25
     * @return
26
     */
27
    public String toString()
28
    {
29
        return String.format("%.03f",  toSecs());
30
    }
31
 
32
    /*
33
     * Returns elapsed time as seconds and fractions of a second
34
     */
35
    public double toSecs()
36
    {
37
        return ((System.nanoTime() - startTime)/1000000000.0);
38
    }
39
 
40
    public int toIntSecs()
41
    {
42
        return (int)(toSecs() + 0.5);
43
    }
44
 
45
    static public String getTimeStamp()
46
    {
47
        return new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(Calendar.getInstance().getTime());
48
    }
49
}