Java Time Format formatTime(int time)

Here you can find the source of formatTime(int time)

Description

format Time

License

LGPL

Declaration

public static String formatTime(int time) 

Method Source Code

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

public class Main {
    private static final int SECONDS_PER_HOUR = 3600;
    private static final int MINUTES_PER_HOUR = 60;
    private static final int SECONDS_PER_MINUTE = 60;

    public static String formatTime(int time) {
        int hours = time / SECONDS_PER_HOUR;
        int minutes = (time - hours * SECONDS_PER_HOUR) / MINUTES_PER_HOUR;
        int seconds = time % SECONDS_PER_MINUTE;

        if (hours == 0)
            return padz(minutes + "", 2) + ":" + padz(seconds + "", 2);
        return hours + "h" + padz(minutes + "", 2);
    }/*from   w  w  w.  j a v a2 s  . c  o m*/

    public static String padz(String s, int n) {
        String ns = "00000000" + s;
        return ns.substring(ns.length() - n);
    }
}

Related

  1. formatTime(int secs)
  2. formatTime(int time)
  3. formatTime(int time)
  4. formatTime(int time)
  5. formatTime(int time)
  6. formatTime(int value)
  7. formatTime(Integer hour, Integer minute, Integer second, Integer ampm, Integer zoneOffset)
  8. formatTime(Integer seconds)
  9. formatTime(long dtNanos)