Java Minute Get getHoursMinutesSeconds(float timeInSeconds)

Here you can find the source of getHoursMinutesSeconds(float timeInSeconds)

Description

Returns a string in the form hours:minutes:seconds for timeInSeconds .

License

Apache License

Declaration

public static String getHoursMinutesSeconds(float timeInSeconds) 

Method Source Code

//package com.java2s;
/*//w w  w.  j a v a2s . c o  m
 * Copyright (C) 2010 Google Inc.
 * 
 * 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 {
    /**
     * Returns a string in the form hours:minutes:seconds for {@code
     * timeInSeconds}. If hours is 0, it will be omitted.
     */
    public static String getHoursMinutesSeconds(float timeInSeconds) {
        int hours = (int) (timeInSeconds / 60 / 60);
        int minutes = (int) (timeInSeconds / 60) - (hours * 60);
        int seconds = (int) (timeInSeconds - (hours * 60 * 60) - (minutes * 60));

        if (hours == 0) {
            return String.format("%d:%02d", minutes, seconds);
        } else {
            return String.format("%d:%02d:%02d", hours, minutes, seconds);
        }
    }
}

Related

  1. getElapsedTimeHoursMinutesFromMilliseconds(long milliseconds)
  2. getFiveMinuteCronByHostId(long hostId)
  3. getFrequencyValueInMinutes(long value)
  4. getHMTimeInMinutes(final String timeStr)
  5. getHourMinuteSecond(long misSecond)
  6. getLessThanOneMinuteAgoRendering()
  7. getMilliSecondFromMinute(int minute)
  8. getMin()
  9. getMin(String dateTime)