在我的应用程序中,我可以为一周中的任何一天设置闹钟,我想显示一个祝酒词,直到下一个闹钟,我为每天设置一个值:
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();
答案 0 :(得分:1)
为了得到这一天,你可以做到
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.
答案 1 :(得分:0)
Date date = calendar.add(Date, 1);
这会给你第二天的校准。 获取日期和号码:
String dayname = date.toString().substring(0, 3);
String temp = date.toString().substring(8, 10);
Integer day = Integer.parseInt(temp);