Java Second Convert secondConvertToString(final long spentSeconds)

Here you can find the source of secondConvertToString(final long spentSeconds)

Description

Convert the seconds to jira format (1h 30m) String.

License

Apache License

Parameter

Parameter Description
spentSeconds The spent seconds.

Return

The result String.

Declaration

public static String secondConvertToString(final long spentSeconds) 

Method Source Code

//package com.java2s;
/*//from   ww w .ja v a  2  s  .  com
 * Copyright (C) 2011 Everit Kft. (http://www.everit.org)
 *
 * 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 number of work hours per day.
     */
    public static final int WORK_HOURS_PER_DAY = 8;
    /**
     * The number of minutes per hour.
     */
    public static final int MINUTES_PER_HOUR = 60;
    /**
     * The number of seconds per minute.
     */
    public static final int SECONDS_PER_MINUTE = 60;

    /**
     * Convert the seconds to jira format (1h 30m) String.
     *
     * @param spentSeconds
     *          The spent seconds.
     * @return The result String.
     */
    public static String secondConvertToString(final long spentSeconds) {
        String summaryString = "";
        long spentMin = spentSeconds / SECONDS_PER_MINUTE;
        long spentHour = spentMin / MINUTES_PER_HOUR;
        long days = spentHour / WORK_HOURS_PER_DAY;
        long hours = spentHour % WORK_HOURS_PER_DAY;
        long mins = spentMin % MINUTES_PER_HOUR;
        if (days != 0) {
            summaryString = days + "d " + hours + "h " + mins + "m";
        } else if (hours != 0) {
            summaryString = hours + "h " + mins + "m";
        } else {
            summaryString = mins + "m";
        }
        return summaryString;
    }
}

Related

  1. convertTimeSecondsToHMS(long longSecs)
  2. convertTimeToSeconds(String a_time)
  3. convertToSeconds(String time)
  4. convertToSeconds(String timeStr)
  5. convertToTenthsOfASecond(long epochSeconds, int nanos)
  6. seconds2microseconds(double secs)
  7. seconds2String(long seconds)
  8. seconds2time(long seconds)
  9. seconds2timecents(double seconds)