Example usage for java.util.concurrent TimeUnit HOURS

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

Introduction

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

Prototype

TimeUnit HOURS

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

Click Source Link

Document

Time unit representing sixty minutes.

Usage

From source file:Main.java

/**
 * Gets a long value i.e the time when the call was made and then returns a
 * appropriate string/*ww w  . j  ava2  s  .c o  m*/
 *
 * @param callDate a long value which represents the time when the call was made
 * @return a formatted string to be displayed.
 */
public static String getTheTimePassedSinceCall(long callDate) {

    long difference = System.currentTimeMillis() - callDate;

    long diffInSeconds = getDateDiff(difference, TimeUnit.SECONDS);
    long diffInMin = getDateDiff(difference, TimeUnit.MINUTES);
    long diffInHours = getDateDiff(difference, TimeUnit.HOURS);

    return getDifferenceString(diffInSeconds, diffInMin, diffInHours, callDate);
}

From source file:Main.java

public static String convertToReadableTime(long milliseconds, boolean includeHours) {

    if (includeHours) {
        // format hh:mm:ss
        return String.format(Locale.ENGLISH, "%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(milliseconds),
                TimeUnit.MILLISECONDS.toMinutes(milliseconds) % TimeUnit.HOURS.toMinutes(1),
                TimeUnit.MILLISECONDS.toSeconds(milliseconds) % TimeUnit.MINUTES.toSeconds(1));
    } else if (TimeUnit.MILLISECONDS.toHours(milliseconds) < 1) {
        // format mm:ss
        return String.format(Locale.ENGLISH, "%02d:%02d",
                TimeUnit.MILLISECONDS.toMinutes(milliseconds) % TimeUnit.HOURS.toMinutes(1),
                TimeUnit.MILLISECONDS.toSeconds(milliseconds) % TimeUnit.MINUTES.toSeconds(1));
    } else {/* w  ww.ja v  a  2  s  . com*/
        return null;
    }

}

From source file:Main.java

public static int parseDuration(String dur) {
    if (TextUtils.isEmpty(dur))
        return 0;
    String[] strings = dur.split(":");
    if (strings.length != 3)
        return 0;
    try {//from w  w  w  .j  a v a  2s . co  m
        int sec = 0;
        if (!TextUtils.isEmpty(strings[0])) {
            sec += TimeUnit.SECONDS.convert(Integer.decode(strings[0]), TimeUnit.HOURS);
        }
        sec += TimeUnit.SECONDS.convert(Integer.decode(strings[1]), TimeUnit.MINUTES);
        sec += TimeUnit.SECONDS.convert(Integer.decode(strings[2].substring(0, 2)), TimeUnit.SECONDS);
        return sec;
    } catch (NumberFormatException e) {
        return 0;
    }

}

From source file:org.z.global.util.TimeValue.java

public static TimeValue timeValueHours(long hours) {
    return new TimeValue(hours, TimeUnit.HOURS);
}

From source file:org.eclipse.gyrex.admin.ui.jobs.internal.ManageJobQueuePage.java

static String toRelativeTime(final long duration) {
    if (duration < TimeUnit.MINUTES.toMillis(2))
        return "a minute";
    else if (duration < TimeUnit.HOURS.toMillis(2))
        return String.format("%d minutes", TimeUnit.MILLISECONDS.toMinutes(duration));
    else//from  ww  w  . ja va2 s .  com
        return String.format("%d hours", TimeUnit.MILLISECONDS.toMinutes(duration));
}

From source file:org.eclipse.gyrex.jobs.internal.storage.CloudPreferencesCleanupJobProvider.java

static void triggerCleanUp() {
    if (preventAutomaticCleanup)
        return;/*from ww w .  j a v  a  2s.c  o m*/
    final long last = lastCleanup.get();
    if ((System.currentTimeMillis() - last) > TimeUnit.HOURS.toMillis(3)) {
        if (lastCleanup.compareAndSet(last, System.currentTimeMillis())) {
            try {
                final IRuntimeContext context = JobsActivator.getInstance()
                        .getService(IRuntimeContextRegistry.class).get(Path.ROOT);
                if (context == null)
                    throw new IllegalStateException("Root context not available!");
                final IJobManager jobManager = context.get(IJobManager.class);
                if (jobManager == null)
                    throw new IllegalStateException("Job manager not available!");
                final IJob cleanupJob = jobManager.getJob(CLEANUP_JOB_ID);
                if ((cleanupJob == null) || (cleanupJob.getState() == JobState.NONE)) {
                    jobManager.queueJob(CLEANUP_JOB_TYPE, CLEANUP_JOB_ID, null, null,
                            "automatic cleanup triggered by " + JobsActivator.getInstance()
                                    .getService(INodeEnvironment.class).getNodeId());
                }
            } catch (final Exception e) {
                LOG.warn("Unable to queue job data cloud cleanup. Staring locally. {}", e.getMessage(), e);
                new CloudPreferencesCleanupJob().schedule();
            }
        }
    }
}

From source file:Main.java

/**
 * Convert a millisecond duration to a string format
 *
 * @param millis//from w ww .ja  v  a 2s  .co m
 *      A duration to convert to a string form
 * @return A string of the form "X Days Y Hours Z Minutes A Seconds".
 */
public static String getDurationBreakdown(long millis, final boolean showMS) {
    if (millis <= 0) {
        return "-";
    }

    final long days = TimeUnit.MILLISECONDS.toDays(millis);
    millis -= TimeUnit.DAYS.toMillis(days);
    final long hours = TimeUnit.MILLISECONDS.toHours(millis);
    millis -= TimeUnit.HOURS.toMillis(hours);
    final long minutes = TimeUnit.MILLISECONDS.toMinutes(millis);
    millis -= TimeUnit.MINUTES.toMillis(minutes);
    final long seconds = TimeUnit.MILLISECONDS.toSeconds(millis);
    millis -= TimeUnit.SECONDS.toMillis(seconds);

    final StringBuilder sb = new StringBuilder();
    if (days > 0) {
        sb.append(days);
        sb.append("d ");
    }
    if (hours > 0) {
        sb.append(String.format("%02d", hours));
        sb.append("h ");
    }
    if (minutes > 0) {
        sb.append(String.format("%02d", minutes));
        sb.append("min ");
    }
    if (seconds > 0) {
        sb.append(String.format("%02d", seconds));
        sb.append("s");
    }
    if ((seconds <= 0) && (millis > 0) && showMS) {
        sb.append(String.format("%02d", millis));
        sb.append("ms");
    }

    return sb.toString();
}

From source file:app.service.FetchService.java

@Autowired
public FetchService(CollectionService colService) {
    mColService = colService;//from   w  ww.j  a  va 2s.  c  o m

    mUrlInfoCache = CacheBuilder.newBuilder().initialCapacity(100).maximumSize(500)
            .expireAfterWrite(2, TimeUnit.HOURS).build();
}

From source file:com.qpark.eip.core.spring.statistics.impl.AppUserStatisticsChannelAdapter.java

/**
 * @param millis/* w w  w.  j a v  a2s. c  o m*/
 * @return the duration in 000:00:00.000 format.
 */
static String getDuration(final long millis) {
    String hmss = String.format("%03d:%02d:%02d.%03d", 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)),
            TimeUnit.MILLISECONDS.toMillis(millis)
                    - TimeUnit.SECONDS.toMillis(TimeUnit.MILLISECONDS.toSeconds(millis)));
    return hmss;
}

From source file:org.ambientlight.config.room.entities.climate.DayEntry.java

public DayEntry(byte high, byte low) {
    int value = MaxUtil.byteArrayToInt(new byte[] { high, low }, 0, 2);
    int timeInMinutes = (value & 0x1FF) * 5;
    temp = ((value >> 9) & 0x3F) / 2.0f;

    hour = (int) TimeUnit.MINUTES.toHours(timeInMinutes);
    min = (int) TimeUnit.MINUTES.toMinutes(timeInMinutes) - (int) TimeUnit.HOURS.toMinutes(hour);
}