Java Time Format formatTime(long timeInSecond)

Here you can find the source of formatTime(long timeInSecond)

Description

format Time

License

Open Source License

Declaration

public static String formatTime(long timeInSecond) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2012 Australian Nuclear Science and Technology Organisation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*  w w  w.  jav  a 2 s  .c o  m*/
 *     Bragg Institute - initial API and implementation
 ******************************************************************************/

public class Main {
    public static String formatTime(long timeInSecond) {
        long hour = timeInSecond / (60 * 60);
        long minute = (timeInSecond - (hour * 60 * 60)) / 60;
        long second = timeInSecond % 60;
        StringBuilder builder = new StringBuilder();
        if (hour < 10) {
            builder.append("0" + hour);
        } else {
            builder.append(hour);
        }
        builder.append(":");
        if (minute < 10) {
            builder.append("0" + minute);
        } else {
            builder.append(minute);
        }
        builder.append(":");
        if (second < 10) {
            builder.append("0" + second);
        } else {
            builder.append(second);
        }
        return builder.toString();
    }
}

Related

  1. formatTime(long time, String syntax, boolean extraZeros)
  2. formatTime(long timeDiff)
  3. formatTime(long timeDiff)
  4. formatTime(long timeDiffMillis)
  5. formatTime(long timeInMilli)
  6. formatTime(long timeInterval, int maxTerms)
  7. formatTime(long timeMillis)
  8. formatTime(long value)
  9. FormatTime(String strTime, char TimeSepartor)