Example usage for java.util.concurrent TimeUnit MILLISECONDS

List of usage examples for java.util.concurrent TimeUnit MILLISECONDS

Introduction

In this page you can find the example usage for java.util.concurrent TimeUnit MILLISECONDS.

Prototype

TimeUnit MILLISECONDS

To view the source code for java.util.concurrent TimeUnit MILLISECONDS.

Click Source Link

Document

Time unit representing one thousandth of a second.

Usage

From source file:Main.java

public static int getSeconds(long milliseconds) {
    return (int) TimeUnit.MILLISECONDS.toSeconds(milliseconds) % SIXTY_SECONDS;
}

From source file:Main.java

/**
 @param time input in milliseconds TODO: covert to seconds
 *//*from ww  w  .  ja  v  a2 s  .c o m*/
public static String formatTimeMinutes(long time) {
    return String.format("%02d:%02d", TimeUnit.MILLISECONDS.toHours(time), TimeUnit.MILLISECONDS.toMinutes(time)
            - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(time)));
}

From source file:Main.java

public static int diffDate(Date fromDay, Date toDay) {

    long from = fromDay.getTime();
    long to = toDay.getTime();
    return (int) TimeUnit.MILLISECONDS.toDays(to - from);
}

From source file:Main.java

public static String getFormattedTimeInterval(long millis) {
    return String.format(Locale.US, "%02d:%02d", TimeUnit.MILLISECONDS.toMinutes(millis),
            TimeUnit.MILLISECONDS.toSeconds(millis)
                    - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)));
}

From source file:Main.java

public static long timeInMinutes(long time) {
    return TimeUnit.MILLISECONDS.toMinutes(time);
}

From source file:Main.java

public static long timeInSeconds(long time) {
    return TimeUnit.MILLISECONDS.toSeconds(time);
}

From source file:Main.java

public static ThreadPoolExecutor createSingleThreadedPoolExecutor() {
    return new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
}

From source file:Main.java

/**
 * Builds String output of time in the style of: HH:MM:SS
 * @param millis/* www. j a  va2s  . c  o  m*/
 * @return
 */
public static String buildTimerStyleTime(long millis) {
    return String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(millis),
            TimeUnit.MILLISECONDS.toMinutes(millis)
                    - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millis)),
            TimeUnit.MILLISECONDS.toSeconds(millis)
                    - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis))

    );
}

From source file:Main.java

public static void runOSCommand(String command) {
    ProcessBuilder builder = new ProcessBuilder("/bin/sh", "-c", command);
    try {//from  w w w  .ja  v a 2  s  . c  o  m
        Process p = builder.start();
        p.waitFor(5000, TimeUnit.MILLISECONDS);
    } catch (IOException | InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:Main.java

public static String printTime(long time, TimeUnit unit) {
    long ns = TimeUnit.NANOSECONDS.convert(time, unit);
    long us = TimeUnit.MICROSECONDS.convert(time, unit);
    long ms = TimeUnit.MILLISECONDS.convert(time, unit);
    long secs = TimeUnit.SECONDS.convert(time, unit);

    if (secs > 0)
        return secs + "s";
    if (ms > 0)
        return ms + "ms";
    if (us > 0)
        return us + " us";
    return ns + "ns";
}