convert Millis To Time From Now - Android android.app

Android examples for android.app:AlarmManager

Description

convert Millis To Time From Now

Demo Code

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.SystemClock;
import android.util.Log;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class Main{

    private static String convertMillisToTimeFromNow(long delayMillis) {
        long one_date_time = 1000 * 60 * 60 * 24;
        long diffDays = (delayMillis) / one_date_time;

        long one_hour_time = 1000 * 60 * 60;
        long diffHours = (delayMillis - (diffDays * one_date_time))
                / one_hour_time;//from w w  w  . j  a v  a  2 s .  co  m

        long one_minute_time = 1000 * 60;
        long diffMinute = (delayMillis - (diffDays * one_date_time) - (diffHours * one_hour_time))
                / one_minute_time;

        StringBuilder sb = new StringBuilder();
        if (0 != diffDays) {
            sb.append(diffDays);
            sb.append(" ");
        }
        if (0 != diffHours) {
            sb.append(diffHours);
            sb.append("?");
        }
        if (0 == diffMinute) {
            diffMinute += 1;
        }
        sb.append(diffMinute);
        sb.append(" ");

        return sb.toString();
    }

}

Related Tutorials