Here you can find the source of convertMillisToHoursMinutesSeconds(long offset)
Parameter | Description |
---|---|
offset | the offset to be converted |
static public String convertMillisToHoursMinutesSeconds(long offset)
//package com.java2s; //License from project: Apache License public class Main { /**/*w w w .ja va 2 s . co m*/ * Converts a millisecond offset into a * friendlier hh:mm:ss format & returns the string. If time is less than one * hour, returns mm:ss only. * * @param offset the offset to be converted * @return the String representation of the time value */ static public String convertMillisToHoursMinutesSeconds(long offset) { return convertSecondsToHoursMinutesSeconds((int) (offset / 1000)); } /** * Converts a second offset into a * friendlier hh:mm:ss format & returns the string. If time is less than one * hour, returns mm:ss only. * * @param offset the offset to be converted * @return the String representation of the time value */ static public String convertSecondsToHoursMinutesSeconds(int offset) { int seconds = offset; int minutes = seconds / 60; int hours = minutes / 60; String strSeconds = new String(); String strMinutes = new String(); seconds = seconds - (minutes * 60); minutes = minutes - (hours * 60); if (seconds < 10) { strSeconds = "0" + seconds; } else { strSeconds = "" + seconds; } if ((minutes < 10) && (hours > 0)) { strMinutes = "0" + minutes; } else { strMinutes = "" + minutes; } if (hours > 0) { return (hours + ":" + strMinutes + ":" + strSeconds); } else { return (strMinutes + ":" + strSeconds); } } }