is there any way to shorten this code? In the code, times of microseconds are converted into minutes and seconds. For example 305862000 ms = 05:05 (5 min : 5 sec).
public static String timeFormatter (long microtime) {
String time = null, timemin = null, timesec = null;
long min = 0;
long sec = 0;
// check if time is negative
if (microtime < 0) {
throw new RuntimeException("Negativ time value provided");
} else {
min = (long) (microtime/(Math.pow((double) 10,(double) 6))/60);
if (min < 10) {
timemin = "0" + min;
// check if time is too long
} else if (min > 99) {
throw new RuntimeException("Time value exceeds allowed format");
} else {
timemin = min + "";
}
microtime = (long) (microtime - min*60*Math.pow((double) 10, (double) 6));
sec = (long) (microtime/Math.pow(10, 6));
if (sec < 10) {
timesec = "0" + sec;
} else {
timesec = sec + "";
}
time = timemin + ":" + timesec;
}
return time;
}