0

Plz explain this. " firstDay = (2 + numDays) % 7; firstDay;"

to get the first day of the month

14th Apr 2018, 3:56 AM
Tanha Badal
Tanha Badal - avatar
5 Respuestas
+ 1
Is it calculating what the day of the week will be? Because if so that won't work as that depends on the year. and if it is what date the first of the month is the. this is pointless because it is always 1. So I'm a little confused exactly what this is trying to do.
14th Apr 2018, 4:09 AM
Adam
Adam - avatar
0
yes someone used to calculate the first day of the month
14th Apr 2018, 4:11 AM
Tanha Badal
Tanha Badal - avatar
0
plz can u explain just the working this only statement
14th Apr 2018, 4:11 AM
Tanha Badal
Tanha Badal - avatar
0
int FirstDayOfMonth(int year,int month) { int t[12] = {0,3,2,5,0,3,5,1,4,6,2,4}; int y = year - (month < 2); y=(y + y/4 - y/100 + y/400 + t[month]+1) % 7; // y = 0 for Sunday, 1 for Monday.. etc. return y; } and how this is working
14th Apr 2018, 4:40 AM
Tanha Badal
Tanha Badal - avatar
0
This is probably the best explanation of this algorithm. Sorry it took me a while to find it again. https://www.quora.com/How-does-Tomohiko-Sakamotos-Algorithm-work
14th Apr 2018, 5:46 AM
Adam
Adam - avatar