C++基于蔡基姆拉尔森计算公式实现由年月日确定周几的方法基于蔡基姆拉尔森计算公式实现由年月日确定周几的方法
示例示例
主要介绍了C++基于蔡基姆拉尔森计算公式实现由年月日确定周几的方法,涉及C++针对日期时间的数值运算相
关操作技巧,需要的朋友可以参考下
本文实例讲述了C++基于蔡基姆拉尔森计算公式实现由年月日确定周几的方法。分享给大家供大家参考,具体如下:
#include <iostream>
#include <string>
using namespace std;
int whatday(int y, int m, int d) {
// 返回正确的星期。用 0 - 6 表示 星期 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:这里再为大家推荐几款时间及日期相关工具供大家参考使用::这里再为大家推荐几款时间及日期相关工具供大家参考使用:
在线日期在线日期/天数计算器:天数计算器:
http://tools.jb51.net/jisuanqi/date_jisuanqi
在线日期计算器在线日期计算器/相差天数计算器:相差天数计算器:
http://tools.jb51.net/jisuanqi/datecalc
在线日期天数差计算器:在线日期天数差计算器:
http://tools.jb51.net/jisuanqi/onlinedatejsq
Unix时间戳时间戳(timestamp)转换工具:转换工具:
http://tools.jb51.net/code/unixtime
希望本文所述对大家C++程序设计有所帮助。