Here you can find the source of timeFormatNano(long delta)
Parameter | Description |
---|---|
delta | a parameter |
private static String timeFormatNano(long delta)
//package com.java2s; /******************************************************************************* * Copyright (c) Nov 2, 2012 NetXForge.//from w ww. j a v a2 s . c om * * This program 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. * * This program 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/> * * Contributors: Christophe Bouhier - initial API and implementation and/or * initial documentation *******************************************************************************/ import java.text.DateFormat; import java.text.DecimalFormat; import java.util.Date; public class Main { public static final double ONE_BILLION = 1E+9; public static final double ONE_MILLION = 1E+6; public static final DecimalFormat FORMAT_DOUBLE_NO_FRACTION = new DecimalFormat( "00"); /** * @param delta * @return */ private static String timeFormatNano(long delta) { StringBuilder sb = new StringBuilder(); // double rest = 0; // @SuppressWarnings("unused") // String[] units = new String[] { "(min:sec:ms)", "(sec)", "(ms)" }; // @SuppressWarnings("unused") // String unit = ""; // int granularity = 2; // In minutes; if (delta > ONE_BILLION * 60) { sb.append(FORMAT_DOUBLE_NO_FRACTION.format(delta / (ONE_BILLION * 60)) + ":"); // granularity--; } else { sb.append("00:"); } // In seconds if (delta > ONE_BILLION) { sb.append(FORMAT_DOUBLE_NO_FRACTION.format(delta / ONE_BILLION) + "::"); // granularity--; } else { sb.append("00::"); } // In mili seconds if (delta > ONE_MILLION) { sb.append(FORMAT_DOUBLE_NO_FRACTION.format(delta / ONE_MILLION)); // granularity--; } else { sb.append("000"); } // even less // if (delta > ONE_THOUSAND) { // sb.append(FORMAT_DOUBLE_NO_FRACTION.format(delta / ONE_THOUSAND)); // // granularity--; // } sb.append(" (min:sec::ms)"); return sb.toString(); } public static String toString(Date date) { return DateFormat.getDateInstance().format(date); } }