Here you can find the source of walltimeFromSeconds(long walltimeSecs)
Parameter | Description |
---|---|
walltimeSecs | seconds |
public static String walltimeFromSeconds(long walltimeSecs)
//package com.java2s; /*//ww w .ja v a2 s . co m * Copyright 1999-2008 University of Chicago * * 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 { /** * Converts seconds into a human readable walltime string with as many * H's as necessary. Mainly doing this for human readable logging. * @param walltimeSecs seconds * @return time string */ public static String walltimeFromSeconds(long walltimeSecs) { if (walltimeSecs < 0 || walltimeSecs == 0) { return "00:00:00"; } final long hours = walltimeSecs / 3600; final long hoursDiff = walltimeSecs - hours * 3600; final long minutes = hoursDiff / 60; final long seconds = walltimeSecs - hours * 3600 - minutes * 60; final StringBuffer buf = new StringBuffer(16); appenNum(buf, hours, false); appenNum(buf, minutes, false); appenNum(buf, seconds, true); return buf.toString(); } private static void appenNum(StringBuffer buf, long num, boolean end) { if (num == 0 && !end) { buf.append("00"); } else if (num < 10) { buf.append("0").append(num); } else { buf.append(num); } if (!end) { buf.append(":"); } } }