• 手机版

    扫码体验手机版

  • 微信公众号

    扫码关注公众号

国内首家协议开发

软芯音视解码保护平台

在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

日期相差天数有关公元前



下面附上我的代码 公元之后的我写了 公元前还没有
#include
using namespace std;


class Date
{
friend int Delta(Date d1, Date d2)
{
  int days = 0;
  if (d1.year > 0&&d2.year > 0)
  {
   for (int i = d1.year; i < d2.year; i++)
   {
    if ((i % 4 == 0 && i % 100 == 0) || i % 400 == 0)
     days += 366;
    else
     days += 365;
   }
  }
  else
  {
   for (int i = d1.year; i < d2.year; i++)
   {
    if (((i+1) % 4 == 0 && (i+1) % 100 == 0) || (i+1) % 400 == 0)
     days += 366;
    else
     days += 365;
   }
  }
  if (d1.month > 0)
  {
   for (int j = 1; j < d1.month; j++)
   {
    if (j == 1 || j == 3 || j == 5 || j == 7 || j == 8 || j == 10 || j == 12)
     days -= 31;
    else if (j == 4 || j == 6 || j == 9 || j == 11)
     days -= 30;
    else if (j == 2)
    {
     if ((d1.year % 4 == 0 && d1.year % 10 == 0) || d1.year % 400 == 0)
      days -= 29;
     else
      days -= 28;
    }
   }
  }
  else
  {


  }
  days -= d1.day;
  if (d2.month > 0)
  {
   for (int k = 1; k < d2.month; k++)
   {
    if (k == 1 || k == 3 || k == 5 || k == 7 || k == 8 || k == 10 || k == 12)
     days += 31;
    else if (k == 4 || k == 6 || k == 9 || k == 11)
     days += 30;
    else if (k == 2)
    {
     if ((d2.year % 4 == 0 && d2.year % 10 == 0) || d2.year % 400 == 0)
      days += 29;
     else
      days += 28;
    }
   }
  }
  else
  {



  }
  days += d2.day;
  return days;
}
friend std::istream & operator>>(std::istream & is, const Date &d)
{
  is >> d.year;
  cout > d.month;
  cout > d.day;
  cout > date1 >> date2;
int delt = Delta(date2, date1);
cout

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

发新帖

发布任务需求已有1031168位用户正在使用天盟网服务

发布分类: *
任务预算: *
需求内容: *
手机号码: *
任务商家报价为
  • 预算价 :
  • 成交价 :
  • 完工期 :
  • 质保期 :

* 最终任务项目以服务商报价、双方协商为准!