Here you can find the source of PrintDuration(long NanoSeconds)
public static String PrintDuration(long NanoSeconds)
//package com.java2s; /* =========================================================================== * Copyright (C) 2015 CapsicoHealth Inc. * * 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./*from w w w .j a v a2 s. com*/ */ public class Main { public static String PrintDuration(long NanoSeconds) { long d = (long) Math.floor(NanoSeconds / (24 * 60 * 60 * 1000000000.0)); NanoSeconds -= d * 24 * 60 * 60 * 1000000000; long h = (long) Math.floor(NanoSeconds / (60 * 60 * 1000000000.0)); NanoSeconds -= h * 60 * 60 * 1000000000; long mn = (long) Math.floor(NanoSeconds / (60 * 1000000000.0)); NanoSeconds -= mn * 60 * 1000000000; long s = (long) Math.floor(NanoSeconds / 1000000000.0); NanoSeconds -= s * 1000000000; long ms = NanoSeconds / 1000000; StringBuilder Str = new StringBuilder(); if (d != 0) Str.append(d).append("d"); if (h != 0 || Str.length() != 0) Str.append(Str.length() != 0 ? " " : "").append(h).append("h"); if (mn != 0 || Str.length() != 0) Str.append(Str.length() != 0 ? " " : "").append(mn).append("mn"); if (s != 0 || Str.length() != 0) Str.append(Str.length() != 0 ? " " : "").append(s).append("s"); if (ms != 0) Str.append(Str.length() != 0 ? " " : "").append(ms).append("ms"); return Str.toString(); } }