Android Second to Time getTime(int minutes, int seconds)

Here you can find the source of getTime(int minutes, int seconds)

Description

Returns a String formatted with minutes and seconds.

License

Apache License

Declaration

public static String getTime(int minutes, int seconds) 

Method Source Code

//package com.java2s;
/*/*from  ww w.  j  a  v a  2s .co  m*/
 * Copyright 2009 Yannick Stucki (yannickstucki.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    /**
     * The smallest number with two digits. Everything below has only one digit
     * and therefore needs to be prepended by a 0 to have two digits.
     */
    private static final int HAS_TWO_DIGITS = 10;

    /**
     * Returns a String formatted with minutes and seconds.
     */
    public static String getTime(int minutes, int seconds) {
        return getTwoDigitNumber(minutes) + ":"
                + getTwoDigitNumber(seconds);
    }

    /**
     * Returns a string of an integer which is at least two digits long. The first
     * digit is filled witha 0 if needed.
     */
    private static String getTwoDigitNumber(int number) {
        return (number < HAS_TWO_DIGITS ? "0" : "")
                + Integer.toString(number);
    }
}

Related

  1. getTimeRemaining(long durationInMilliseconds)
  2. timeRemaining(double seconds)
  3. getDfferenceInMinute(long miliseconds)
  4. getTimeForm(long milliseconds)
  5. milliSecondsToTimer(long milliseconds)
  6. getElapsedSeconds(long start, long end)
  7. getSpeedString(float bytesPerMillisecond)
  8. getSeconds1()
  9. getSeconds2()