Java Long Number to Time toTextTime(long time)

Here you can find the source of toTextTime(long time)

Description

to Text Time

License

Open Source License

Declaration

public static String toTextTime(long time) 

Method Source Code

//package com.java2s;
/*/*from  w ww .  j  a va2 s.  co  m*/
 * Copyright 2007 Zhang, Zheng <oldbig@gmail.com>
 * 
 * This file is part of ZOJ.
 * 
 * ZOJ is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either revision 3 of the License, or (at your option) any later revision.
 * 
 * ZOJ is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with ZOJ. if not, see
 * <http://www.gnu.org/licenses/>.
 */

public class Main {
    public static String toTextTime(long time) {
        long h = time / 3600;
        long m = time % 3600 / 60;
        long s = time % 60;
        StringBuilder sb = new StringBuilder();
        if (h > 0) {
            sb.append(h);
            sb.append(" Hour");
            if (h > 1) {
                sb.append("s");
            }
            sb.append(" ");
        }
        if (m > 0) {
            sb.append(m);
            sb.append(" Minute");
            if (m > 1) {
                sb.append("s");
            }
            sb.append(" ");
        }
        if (s > 0) {
            sb.append(s);
            sb.append(" Second");
            if (s > 1) {
                sb.append("s");
            }
            sb.append(" ");
        }

        return sb.toString();
    }
}

Related

  1. stringTolong(String time)
  2. time2Date(Long time)
  3. time2DATETIME(long time)
  4. toLong(String time)
  5. toLongString(long ms)
  6. transformDateTime(long t)