Java Minute Convert convertMillisToHoursMinutesSeconds(long offset)

Here you can find the source of convertMillisToHoursMinutesSeconds(long offset)

Description

Converts a millisecond offset into a friendlier hh:mm:ss format & returns the string.

License

Apache License

Parameter

Parameter Description
offset the offset to be converted

Return

the String representation of the time value

Declaration

static public String convertMillisToHoursMinutesSeconds(long offset) 

Method Source Code

//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);
        }
    }
}

Related

  1. convertDegreeMinuteSecond(double degree, double minute, double second)
  2. convertHoursMinutesSecondsToSeconds(String offset)
  3. convertHoursToMinutes(Double hours)
  4. convertHoursToMinutes(final int hours)
  5. convertMinute(String targetHhMm)
  6. convertMinuteSecond(double minute, double second)
  7. convertMinutesSecondsToMilliseconds(String offset)
  8. convertMinutesToMilliseconds(final long minutes)