Here you can find the source of elapsedNanos(long nanoseconds)
Parameter | Description |
---|---|
nanoseconds | the elapsed time in nanoseconds |
public static String elapsedNanos(long nanoseconds)
//package com.java2s; /*//w ww .j a v a 2s .com * Copyright (C) 2014 Brian L. Browning * * This file is part of Beagle * * Beagle 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 version 3 of the License, or * (at your option) any later version. * * Beagle 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 this program. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Returns a string representation of the specified elapsed time * in the format "H hours M minutes S seconds". * * @param nanoseconds the elapsed time in nanoseconds * * @return a string representation of the specified elapsed time */ public static String elapsedNanos(long nanoseconds) { long seconds = Math.round(nanoseconds / 1000000000.0); StringBuilder sb = new StringBuilder(80); if (seconds >= 3600) { long hours = seconds / 3600; sb.append(hours); sb.append(hours == 1 ? " hour " : " hours "); seconds %= 3600; } if (seconds >= 60) { long minutes = seconds / 60; sb.append(minutes); sb.append(minutes == 1 ? " minute " : " minutes "); seconds %= 60; } sb.append(seconds); sb.append(seconds == 1 ? " second" : " seconds"); return sb.toString(); } }