main.cpp主函式**:
#include
#include
"time.h"
using
namespace std;
void
timetest()
;int
main()
void
timetest()
time.h類標頭檔案**:
#ifndef time_h
#define time_h
#include
using
namespace std;
class
time
intgetmonth()
intgetday()
void
setyear
(int year)
void
setmonth
(int month)
void
setday
(int day)
protected
:private
:int m_year;
int m_month;
int m_day;};
#endif
// time_h
time.cpp
#include 「time.h」
#include
#include
using namespace std;
time::time()
time::time(int year,int month,int day)
;int month2[12] = ;
int runyear= 0;
int pingyear = 0;
int runmonth= 0;
int pingmonth= 0;
if(getyear() < time2.getyear()) //當比較的年份大時
else
else
else
day1 = 30 - getday();}}
for(int i = getmonth() + 1; i < 12 + 1; i++)
}for(int k = 0; k < (sizeof(month2) / sizeof(int)); k++)}}
day2 = day1 + (runmonth * 31) + (pingmonth * 30);
}for(int i = getyear() + 1; i < time2.getyear(); i++)
else
pingyear++;
}day3 = (runyear * 366) + (pingyear * 365);
//計算大的年已經過去的天數
long day4 = 0;
if(time2.getmonth() == 1)
else
else
for(int k = 0; k < (sizeof(month2) / sizeof(int)); k++)
}day4 = runmonth * 31 + pingmonth * 30 + time2.getday();}}
day = day2 + day3 + day4;
cout << "相差 <" << day << "> 天!" << endl;
}else//getyear()為平年,判斷月份,算出到年底的天數
else
else
else
day1 = 30 - getday();}}
for(int i = getmonth() + 1; i < 12 + 1; i++)
}for(int k = 0; k < (sizeof(month2) / sizeof(int)); k++)}}
day2 = day1 + (runmonth * 31) + (pingmonth * 30);
}for(int i = getyear() + 1; i < time2.getyear(); i++)
else
pingyear++;
}day3 = (runyear * 366) + (pingyear * 365);
//計算大的年已經過去的天數
long day4 = 0;
if(time2.getmonth() == 1)
else
else
for(int k = 0; k < (sizeof(month2) / sizeof(int)); k++)
}day4 = runmonth * 31 + pingmonth * 30 + time2.getday();}}
day = day2 + day3 + day4;
cout << "相差 <" << day << "> 天!" << endl;
}}//******年份相等時*****
else if(getyear() == time2.getyear())
for(int k = 0; k < sizeof(month2) / sizeof(int); k++)
}day5 = 31 * runmonth + pingmonth * 30;
if(getmonth() == 1)
else
else
}else
for(int k = 0; k < sizeof(month2) / sizeof(int); k++)}}
}day6 = day5 + day1 + time2.getday();
cout << "相差 <" << day6 << "> 天!" << endl;
}else if(getmonth() == time2.getmonth())//月份相同
}//當比較的年份小時
else
else
else
else
day1 = 30 - time2.getday();}}
for(int i = time2.getmonth() + 1; i < 12 + 1; i++)
}for(int k = 0; k < (sizeof(month2) / sizeof(int)); k++)}}
day2 = day1 + (runmonth * 31) + (pingmonth * 30);
}for(int i = time2.getyear() + 1; i < getyear(); i++)
else
pingyear++;
}day3 = (runyear * 366) + (pingyear * 365);
//計算大的年已經過去的天數
long day4 = 0;
if(getmonth() == 1)
else
else
for(int k = 0; k < (sizeof(month2) / sizeof(int)); k++)
}day4 = runmonth * 31 + pingmonth * 30 + time2.getday();}}
day = day2 + day3 + day4;
cout << "相差 <" << day << "> 天!" << endl;
}else //為平年算出天數
else
else
else
day1 = 30 - time2.getday();}}
for(int i = time2.getmonth() + 1; i < 12 + 1; i++)
}for(int k = 0; k < (sizeof(month2) / sizeof(int)); k++)}}
day2 = day1 + (runmonth * 31) + (pingmonth * 30);
}for(int i = time2.getyear() + 1; i < getyear(); i++)
else
pingyear++;
}day3 = (runyear * 366) + (pingyear * 365);
//計算大的年已經過去的天數
long day4;
if(getmonth() == 1)
else
else
for(int k = 0; k < (sizeof(month2) / sizeof(int)); k++)
}day4 = runmonth * 31 + pingmonth * 30 + time2.getday();}}
day = day2 + day3 + day4;
cout << "相差 <" << day << "> 天!" << endl;}}}
time::~time()
php計算任意兩個日期之間的天數
php計算任意兩個日期之間的天數 基本思想,算術減法 cur date 2009 04 11 last date 2008 12 20 date dist 0000 03 21 間隔大約3個月21天 116天 create function function date distance last d...
C 計算任意兩個日期之間的天數
c 寫的乙個計算兩個日期之間天數的小程式 cpp view plain copy include include struct tagdate 設定日期 void setdate int y,int m,int d,tagdate date 是否閏年 int isleapyear int year ...
計算兩個日期之間的天數
問題描述 給定兩個日期,計算相差的天數。比如2010 1 1和2010 1 3相差2天。時間限制 1000 記憶體限制 65536 輸入共兩行 第一行包含三個整數startyear,startmonth,startday,分別是起始年 月 日。第二行包含三個整數endyear,endmonth,en...