Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.

public enum TimeUnit

  1. Object
  2. Enum<TimeUnit>
  3. TimeUnit

ImplementsComparable<TimeUnit>

A unit of time, for timeouts such as Future.get(long, TimeUnit). Conversions saturate: a value too large for the target unit becomes Long.MAX_VALUE or Long.MIN_VALUE rather than overflowing.

Enum constants

NANOSECONDSBillionths of a second.
MICROSECONDSMillionths of a second.
MILLISECONDSThousandths of a second.
SECONDSSeconds.
MINUTESMinutes.
HOURSHours.
DAYSDays.

Methods

public static TimeUnit[] values()
public static TimeUnit valueOf(String name)
public long convert(long sourceDuration, TimeUnit sourceUnit)sourceDuration in sourceUnit, converted to this unit.
public long toNanos(long d)d of this unit in nanoseconds.
public long toMicros(long d)d of this unit in microseconds.
public long toMillis(long d)d of this unit in milliseconds.
public long toSeconds(long d)d of this unit in seconds.
public long toMinutes(long d)d of this unit in minutes.
public long toHours(long d)d of this unit in hours.
public long toDays(long d)d of this unit in days.
public void timedWait(Object obj, long timeout) throws InterruptedExceptionWaits on obj for timeout of this unit, as obj.wait does.
public void timedJoin(Thread thread, long timeout) throws InterruptedExceptionWaits up to timeout of this unit for thread to end, as thread.join does.
public void sleep(long timeout) throws InterruptedExceptionSleeps for timeout of this unit, as Thread.sleep does.

Inherited methods

Enum constant details

NANOSECONDS

NANOSECONDS
Billionths of a second.

MICROSECONDS

MICROSECONDS
Millionths of a second.

MILLISECONDS

MILLISECONDS
Thousandths of a second.

SECONDS

SECONDS
Seconds.

MINUTES

MINUTES
Minutes.

HOURS

HOURS
Hours.

DAYS

DAYS
Days.

Method details

values

public static TimeUnit[] values()

valueOf

public static TimeUnit valueOf(String name)

convert

public long convert(long sourceDuration, TimeUnit sourceUnit)
sourceDuration in sourceUnit, converted to this unit.

Parameters

sourceDuration long
the duration
sourceUnit TimeUnit
its unit

Returns

the duration in this unit

toNanos

public long toNanos(long d)
d of this unit in nanoseconds.

Parameters

d long
the duration

Returns

the converted duration

toMicros

public long toMicros(long d)
d of this unit in microseconds.

Parameters

d long
the duration

Returns

the converted duration

toMillis

public long toMillis(long d)
d of this unit in milliseconds.

Parameters

d long
the duration

Returns

the converted duration

toSeconds

public long toSeconds(long d)
d of this unit in seconds.

Parameters

d long
the duration

Returns

the converted duration

toMinutes

public long toMinutes(long d)
d of this unit in minutes.

Parameters

d long
the duration

Returns

the converted duration

toHours

public long toHours(long d)
d of this unit in hours.

Parameters

d long
the duration

Returns

the converted duration

toDays

public long toDays(long d)
d of this unit in days.

Parameters

d long
the duration

Returns

the converted duration

timedWait

public void timedWait(Object obj, long timeout) throws InterruptedException
Waits on obj for timeout of this unit, as obj.wait does.

Parameters

obj Object
the monitor, which the caller must hold
timeout long
how long to wait

Throws

InterruptedException
when the thread is interrupted

timedJoin

public void timedJoin(Thread thread, long timeout) throws InterruptedException
Waits up to timeout of this unit for thread to end, as thread.join does.

Parameters

thread Thread
the thread to wait for
timeout long
how long to wait

Throws

InterruptedException
when the waiting thread is interrupted

sleep

public void sleep(long timeout) throws InterruptedException
Sleeps for timeout of this unit, as Thread.sleep does.

Parameters

timeout long
how long to sleep

Throws

InterruptedException
when the thread is interrupted