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++程序设计有所帮助。

人生难免有挫折,但你是逃避不了的,一定要去面对它

C++基于蔡基姆拉尔森计算公式实现由年月日确定周几的方法示例

相关文章:

你感兴趣的文章:

标签云: