I want to run a count down timer that run reverse from next Monday. two date i used. 1. current Date() 2. next Monday date. How i find the next Monday date whenever i run my app according to current time/date ? Thanks.
Using the Date.day property calculate the difference between now and the next Monday.
I have commented the code below and I think it explains it sufficiently
//Get todays date
var now:Date = new Date();
//Set the time to midnight
now.setHours(0,0,0,0);
//Get the day of the week Sun = 0, Mon = 1, etc...
var day:int = now.getDay();
//Will be used to calculate next monday
var dayDifference:int = 0;
//Sunday is the exception to catch
if (day == 0) {
dayDifference = 1;
}
else {
//Every other day the difference can be calculated as 8 - day of the week
dayDifference = 8 - day;
}
//Use the timestamp to setup the next monday date
var nextMonday:Date = new Date(now.time);
//Add the number of days to get next monday
nextMonday.date += dayDifference;
+