// Inspired from http://memorynotfound.com/calculating-elapsed-time-java/
import java.util.concurrent.TimeUnit;

public class Timer{

    long startTime;
    long endTime;

    public Timer() {
	startTime = 0;
	endTime = -1;
    }

    public void start() {
        startTime = System.nanoTime();
    }

    public long end() {
        endTime = System.nanoTime();
        return endTime - startTime;
    }

    public long time() {
        return endTime - startTime;
    }

    public long time(TimeUnit unit) {
        return unit.convert(time(), TimeUnit.NANOSECONDS);
    }

    public String toMinuteSeconds(){
        return String.format("%d min, %d sec", time(TimeUnit.MINUTES),
                time(TimeUnit.SECONDS) - time(TimeUnit.MINUTES));
    }

    public String toString(){
	return String.format("%d", time());
    }
}