Java tutorial
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; public class Main { public static String formatTime(final long totalSeconds, final int timer) { if (timer == 0) { final SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); sdf.setTimeZone(TimeZone.getTimeZone("GMT+0")); return sdf.format(new Date(totalSeconds * 1000)); } else { String seconds = Integer.toString((int) (totalSeconds % 60)); String minutes = Integer.toString((int) (totalSeconds / 60)); if (seconds.length() < 2) { seconds = "0" + seconds; } if (minutes.length() < 2) { minutes = "0" + minutes; } return minutes + ":" + seconds; } } }