get Remaining Time In Milliseconds - Android java.util

Android examples for java.util:Millisecond

Description

get Remaining Time In Milliseconds

Demo Code


import java.util.Calendar;
import java.util.Date;
import java.util.TreeMap;
import android.util.Log;

public class Main{
    private static final long NEXT_DAY_TRASHOLD = 20 * HOURS_TO_MILLIS;
    private static long getRemainingTimeInMillis(Date now, Calendar calendar) {
        final long arrivingTime = calendar.getTimeInMillis();

        final long remainingTimeInMillis = arrivingTime - now.getTime();
        if (remainingTimeInMillis < 0
                && (-remainingTimeInMillis) > NEXT_DAY_TRASHOLD) {
            calendar.add(Calendar.DATE, 1);
            return getRemainingTimeInMillis(now, calendar);
        }//  w  ww  .  j  av a  2 s  .  com
        return remainingTimeInMillis;
    }
}

Related Tutorials