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);
}
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);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments