C + + implements an example of a method to determine the day of the week by year month and day based on zekim larsen calculation formula
- 2020-05-26 09:45:24
- OfStack
In this paper, the method of determining the day of the week by the year, month and day based on the calculation formula of C + + is illustrated. I will share it with you for your reference as follows:
#include <iostream>
#include <string>
using namespace std;
int whatday(int y, int m, int d) {
// Return to the correct week. with 0 - 6 said week 1 - 7
if(m==1||m==2)
{
y--;
m+=12;
}
return(d+2*m+3*(m+1)/5+y+y/4-y/100+y/400)%7;
}
string weekday[7] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
int main() {
int y, m, d;
cin >> y >> m >> d;
cout << weekday[whatday(y, m, d)] << endl;
return 0;
}
PS: here are some other time and date related tools for your reference:
Online date/days calculator:
http://tools.ofstack.com/jisuanqi/date_jisuanqi
Online date calculator/day difference calculator:
http://tools.ofstack.com/jisuanqi/datecalc
Online date days difference calculator:
http://tools.ofstack.com/jisuanqi/onlinedatejsq
Unix timestamp (timestamp) conversion tool:
http://tools.ofstack.com/code/unixtime
I hope this article has helped you with C++ programming.