Java Minute Convert convertSecondsToHoursMinutesSeconds(int offset)

Here you can find the source of convertSecondsToHoursMinutesSeconds(int offset)

Description

Converts a second 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 convertSecondsToHoursMinutesSeconds(int offset) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/* w w  w. jav  a 2s . c om*/
      * 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. convertMinutesToSeconds(final long minutes)
  2. convertMinutesToSeconds(int minutesToConvert)
  3. convertMsToMinutesAndSeconds(long ms)
  4. convertOffsetToMinutesSeconds(int offset)
  5. convertOffsetToMinutesSecondsMillis(int offset)
  6. convertSecondsToMinutes(double seconds)
  7. convertTicksToMinutesAndSeconds(int ticks, boolean fraction)
  8. convertTimemilisecondsToMinutes(long time)
  9. minutesToHHMM(int mins)