Android将毫秒转为时分秒

/**
 * 将毫秒转时分秒
 *
 * @param time
 * @return
 */
public static String generateTime(long time) {
    int totalSeconds = (int) (time / 1000);
    int seconds = totalSeconds % 60;
    int minutes = (totalSeconds / 60) % 60;
    int hours = totalSeconds / 3600;

    return hours > 0 ? String.format("%02dh%02dm%02ds", hours, minutes, seconds) : String.format("%02dm%02ds", minutes, seconds);
}

猜你喜欢

转载自blog.csdn.net/qq_27400335/article/details/79412249
今日推荐