All Downloads are FREE. Search and download functionalities are using the official Maven repository.

rinde.sim.util.TimeFormatter Maven / Gradle / Ivy

There is a newer version: 4.4.6
Show newest version
package rinde.sim.util;

import org.joda.time.Period;
import org.joda.time.PeriodType;
import org.joda.time.format.PeriodFormatter;
import org.joda.time.format.PeriodFormatterBuilder;

/**
 * Provides methods for converting time expressed as a long to a
 * nice string representatation: (D) HH:MM:SS.
 * @author Rinde van Lon 
 */
@Deprecated
public final class TimeFormatter {

  private static PeriodFormatter formatter = new PeriodFormatterBuilder()
      .appendDays().appendSeparator(" ").minimumPrintedDigits(2)
      .printZeroAlways().appendHours().appendLiteral(":").appendMinutes()
      .appendLiteral(":").appendSeconds().toFormatter();

  private TimeFormatter() {}

  /**
   * Converts the specified time in to a string.
   * @param ms The time to format in milliseconds.
   * @return A nice formatted time string.
   */
  public static String format(long ms) {
    return formatter.print(new Period(0, ms, PeriodType.dayTime()));
  }

  /**
   * Converts the specified time to a string.
   * @param ms The time to format in milliseconds.
   * @return A nice formatted time string.
   */
  public static String format(double ms) {
    return format(Math.round(ms));
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy