Java Utililty Methods Milliseconds

List of utility methods to do Milliseconds

Description

The list of methods to do Milliseconds are organized into topic(s).

Method

voidmarsTimeFromElapsedMillis(long elapsedMillis, int[] marsTime)
Calculate the local Mars time from the number of milliseconds since the start of Sol 1.
double marsDaySecs = (double) 35.244 + (double) 24 * 60 * 60 + 39 * 60;
double solDouble = ((double) (elapsedMillis / 1000)) / marsDaySecs;
double hourDouble = (solDouble - ((long) solDouble)) * 24;
double minuteDouble = (hourDouble - ((long) hourDouble)) * 60;
double secondDouble = (minuteDouble - ((long) minuteDouble)) * 60;
int sol = (int) (solDouble) + 1;
int hour = (int) (hourDouble);
int minute = (int) (minuteDouble);
...
longmegaCyclesToMilliseconds(long megaCycles)
mega Cycles To Milliseconds
return (long) (1000 * megaCycles / MCYCLES_PER_SECOND);
longmicrosToMillis(long micros)
Convert microseconds to milliseconds, ensuring that any microsecond value greater than zero converts to at least one millisecond to avoid a zero millisecond result since Object.wait(0) waits forever.
return (micros + 999) / 1000;
longmicrosToMillis(long sec, long usec)
micros To Millis
return sec * 1000 + usec / 1000;
longmilliDate(String date)
Convert a YYYYMMDDHHMMSSTTT date to milliseconds
Calendar cal = new GregorianCalendar();
try {
    cal.set(Integer.parseInt(date.substring(0, 4)), Integer.parseInt(date.substring(4, 6)),
            Integer.parseInt(date.substring(6, 8)), Integer.parseInt(date.substring(8, 10)),
            Integer.parseInt(date.substring(10, 12)), Integer.parseInt(date.substring(12, 14)));
    long milli = cal.getTimeInMillis() + Long.parseLong(date.substring(14));
    return milli;
} catch (Exception e) {
...
longmillisBetween(Date firstDate, Date lastDate)
Retorna o número de milissegundos entre dias dadas
long t1 = firstDate.getTime();
long t2 = lastDate.getTime();
long dif = t1 - t2;
if (dif < 0) {
    dif = dif * (-1);
return dif;
intmillisecond(final Date date)
millisecond
return fromDateToCalendar(date).get(MILLISECOND);
intmillisecondOf(Date date)
Extracts the millisecond of the given Date.
return toCalendar(date).get(Calendar.MILLISECOND);
Datemilliseconds(int offset)
milliseconds
Calendar c = Calendar.getInstance();
c.set(Calendar.MILLISECOND, c.get(Calendar.MILLISECOND) + offset);
return c.getTime();
longmillisecondsBetween(Date start, Date finish)
Returns the number of milliseconds between the given Dates.
Calendar calendar1 = new GregorianCalendar();
calendar1.setTime(start);
Calendar calendar2 = new GregorianCalendar();
calendar2.setTime(finish);
return calendar2.getTimeInMillis() - calendar1.getTimeInMillis();