Android examples for java.util:Date Time
Format Time less than an hour
import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Rect; import android.text.TextUtils; import java.io.DataOutputStream; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.net.URLEncoder; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.Locale; import java.util.Random; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main{ public static String computeTime(long time) { String _time = ""; if (time / 3600 > 1) { } else {//from w w w.jav a 2 s. c om if (time < 60) { if (time < 10) { _time = "00:0" + time; } else { _time = "00:" + time; } } else { if (time % 60 == 0) { if (time / 60 >= 10) { _time = time / 60 + ":" + "00"; } else { _time = "0" + time / 60 + ":" + "00"; } } else { if (time / 60 >= 10) { if (time % 60 >= 10) { _time = time / 60 + ":" + time % 60; } else { _time = time / 60 + ":0" + time % 60; } } else { if (time % 60 >= 10) { _time = "0" + time / 60 + ":" + time % 60; } else { _time = "0" + time / 60 + ":0" + time % 60; } } } } } return _time; } }