package jena; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; public class Timer { long startTime; long endTime; long totalTime; DateFormat dateFormat; public Timer() { /* Constructor - starts the timer. */ dateFormat = new SimpleDateFormat("mm 'minutes,' ss 'seconds' S 'milliseconds'"); dateFormat.setTimeZone(TimeZone.getTimeZone("GMT+1")); startTime = System.currentTimeMillis(); } public String getStartTime() { return new Date(startTime).toString(); } public String getTotalTime() { return dateFormat.format(new Date(totalTime)).toString(); } public String stop (){ /* This method stops the timer and calculates the result. The result is both printed to screen and returned as a string. */ endTime = System.currentTimeMillis(); totalTime = endTime - startTime; System.out.println("Execution time: " + dateFormat.format(new Date(totalTime))); return dateFormat.format(new Date(totalTime)).toString(); } }