在我的应用程序中,我可以设置一周中任何一天的警报,我想显示直到下一次警报为止的时间的吐司,我每天设置一个值:

String[] str = new String[7];
str[0] = getResources().getString(R.string.weeks_sunday);
str[1] = getResources().getString(R.string.weeks_monday);
str[2] = getResources().getString(R.string.weeks_tuesday);
str[3] = getResources().getString(R.string.weeks_wednesday);
str[4] = getResources().getString(R.string.weeks_thursday);
str[5] = getResources().getString(R.string.weeks_friday);
str[6] = getResources().getString(R.string.weeks_Saturday);
weeks = str;


这是我要计算下一次警报的时间,但是我不知道如何知道结束日

    String substr = ":";
    String before =  aTime.substring(0, aTime.indexOf(substr));
    int bef = Integer.parseInt(before);
    String after = aTime.substring(aTime.indexOf(substr) + substr.length());
    int aft = Integer.parseInt(after);

    int year = c.get(Calendar.YEAR);
    int month = c.get(Calendar.MONTH);
    int dayy = c.get(Calendar.DAY_OF_MONTH);

    GregorianCalendar date = new GregorianCalendar();
    long currentTime = date.getTimeInMillis();
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.set(year, month, 22, bef, aft, 0);
    long difference = calendar.getTimeInMillis()-currentTime;

    long x = difference / 1000;
    long seconds = x % 60;
    x /= 60;
    long minutes = x % 60;
    x /= 60;
    long hours = x % 24;
    x /= 24;
    long days = x;



    if(hours == 1){
            Toast.makeText(AddAlarmActivity.this, "Alarm set for " + days + " days, " + hours + " hour and " + minutes + " minutes from now", Toast.LENGTH_LONG).show();
    }else if(hours >= 2){
            Toast.makeText(AddAlarmActivity.this, "Alarm set for " + days + " days, " + hours + " hours and " + minutes + " minutes from now", Toast.LENGTH_LONG).show();

最佳答案

为了得到一天,你可以做

final Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
final int day = calendar.get(Calendar.DAY_OF_WEEK);

switch (day) {
    case Calendar.SUNDAY:

}

// or you can just match the day to your day name string.

07-25 22:13