secret35 secret35 - 6 days ago 6
Android Question

How can I get a day off next week?

How can I get a day off next week from android?

The hour I set for Friday and Sunday is over. I want you to go to friday next week.

This is my code;

/**
* Set Friday Alarm
*/
getNotfDay.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY);
getNotfDay.set(Calendar.HOUR_OF_DAY, myCustomTime.getHours());
getNotfDay.set(Calendar.MINUTE, myCustomTime.getMinutes());
getNotfDay.set(Calendar.SECOND, myCustomTime.getSeconds());

/**
* 30 minute later from alarm time
*/
getNotfDay.add(Calendar.MINUTE, 30);

/**
* If Friday time before currently time is set Sunday
*/
if (getNotfDay.getTime().before(Utils.longToDate(System.currentTimeMillis()))) {
getNotfDay.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
getNotfDay.set(Calendar.HOUR_OF_DAY, myCustomTime2.getHours());
getNotfDay.set(Calendar.MINUTE, myCustomTime2.getMinutes());
}


Utils.java

public static Date longToDate(long timeMillis){
return new Date(timeMillis);
}

Answer

You can just add 7 days (1 week).

//Set to this week's Friday
getNotfDay.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY);
getNotfDay.set(Calendar.HOUR_OF_DAY, myCustomTime.getHours());
getNotfDay.set(Calendar.MINUTE, myCustomTime.getMinutes());
getNotfDay.set(Calendar.SECOND, myCustomTime.getSeconds());
getNotfDay.add(Calendar.DATE, 7);
Comments