1、/ 或是经常使用但不常更改的/ 特定于项目的包含文件#pragma once#includecstringctimeiomanipstdio.h fstreamcmath#include vector#using System.dllSystem.Windows.Forms.dllSystem.Drawing.dll#define LeapYear(y) (y%4=0)&(y%100!=0)|(y%400=0)using namespace std;struct SolarLunarint SolarYear; /阳历年int SolarMonth; /阳历月int SolarDay; /阳历
2、日int LunarYear; /阴历年int LunarMonth; /阴历月int LunarDay; /阴历日int LunarLeapMonth; /阴历闰月标志,1表示此月为闰月,0表示非闰月char holiday9; /节日信息;int djs(int curYear,int curMonth,int curDay,int curHour,int curMin); /倒计时统计int getdays(int year, int month); /计算当前月份天数int getweek(int year, int month, int day); /分析当前月份第一天是星期几int
3、 getsec(System:String s); /转换txt字符为日期并让djs()处理返回秒void SolarToLunar(SolarLunar* p); /阳历转换成农历void GetHoliday(SolarLunar* p); /获得节日信息int GetDayNumber(int year, int month, int day); /判断阳历某一天是该年的第几天int GetTotalDayNumber(int year, int month, int day); /求从阳历1900年1月31日(阴历1900年1月1日)到某年某月某日(阳历)共多少天int LunarYe
4、arDays(int y) ;int IsLeapYear(int year) ;int LunarLeapDays(int y) ;int LunarMonthDays(int y,int m) ;int LunarLeapMonth(int y) ;/djs.cpp 计算时间差的函数#includestdafx.hint djs( int curYear,int curMonth,int curDay,int curHour,int curMin) time_t t; t=time(NULL); struct tm t1, t2, *ptr; ptr=localtime(&t); mems
5、et(&t1, 0x00, sizeof(t1);t2, 0x00, sizeof(t2); int strYear=curYear; int strMon=curMonth; int strDay=curDay; int strHour=curHour; int strMin=curMin; int strSec=0; t1.tm_year = strYear - 1900; t1.tm_mon = strMon - 1; t1.tm_mday = strDay; t1.tm_hour = strHour; t1.tm_min = strMin; t1.tm_sec = strSec; t2
6、.tm_year = ptr-tm_year; t2.tm_mon = ptr-tm_mon; t2.tm_mday = ptr-tm_mday; t2.tm_hour = ptr-tm_hour; t2.tm_min = ptr-tm_min; t2.tm_sec = ptr-tm_sec; time_t start = mktime(&t1); time_t end = mktime(&t2); time_t retSec = start - end ; time_t retMin = retSec/60; /time_t retHour = retMin/60; /time_t retD
7、ay = retHour/24; return (int)retSec;/getweek.cpp #include int getweek(int year, int month, int day) if(month=1|month=2) month+=12; -year; return (day+1+2*month+3*(month+1)/5+year+year/4-year/100+year/400)%7;/getday.cpp int getdays(int year, int month) int days=31,28,31,30,31,30,31,31,30,31,30,31; if
8、(LeapYear(year)&month=2) return 29; else return daysmonth-1;/getsec.cpp 计算时间差的函数/将从txt得到的字符时间转换成整型数 时间差得到秒String s) struct tm t1; memset(& System:String strYear,strMon,strDay,strHour,strMin;String str1(s);/2010-01-01 01:01 strYear = str1-Substring(0, 4); strMon = str1-Substring(5, 2); strDay = str1-
9、Substring(8, 2); strHour = str1-Substring(11, 2); strMin = str1-Substring(14, 2); t1.tm_year = (strYear0-48)*1000+(strYear1-48)*100+(strYear2-48)*10+(strYear3-48) - 1900; t1.tm_mon = (strMon0-48)*10+(strMon1-48) - 1; t1.tm_mday = (strDay0-48)*10+(strDay1-48); t1.tm_hour = (strHour0-48)*10+(strHour1-
10、48); t1.tm_min = (strMin0-48)*10+(strMin1-48); t1.tm_sec = 0; struct tm t2, *ptr;/getsec结束/ SolarToLunar.cpp 阳历到农历的转换/阳历到阴历的转换void SolarToLunar(SolarLunar* p) p-LunarLeapMonth=0; /初始设置当前月不是阴历闰月 int number=GetTotalDayNumber(p-SolarYear, p-SolarMonth, p-SolarDay); int i; for(i=1900; i0; i+) number=num
11、ber-LunarYearDays(i); if(number=0) number=number+LunarYearDays(i-1); /number最终保存了当天是该年(阴历年)的第几天 i-;LunarYear=i; /获得阴历年 int a=LunarLeapMonth(i); /获得阴历年的闰月 int flag=0; /减掉闰月的标志 int j; for(j=1; jLunarLeapMonth=1; /设置当前月是阴历闰月的标记 else number=number+LunarMonthDays(i,j-1); j-;LunarMonth=j; /获得阴历月LunarDay=n
12、umber; /获得阴历日/ holiday.cpp 节日判断(由于调试问题本程序最终应用的时候并没有添加此功能)/获得节日信息void GetHoliday(SolarLunar* p)strcpy(p-holiday,); /初始化int number;number=p-LunarMonth*100 + p-LunarDay; /阴历节日switch(number) case 115: strcpy(p-holiday, 元宵 break;case 505:端午case 707:中元case 815:中秋case 1208:腊八int LunarInfo= 0x04bd8,0x04ae0,
13、0x0a570,0x054d5,0x0d260,0x0d950,0x16554,0x056a0,0x09ad0,0x055d2, 0x04ae0,0x0a5b6,0x0a4d0,0x0d250,0x1d255,0x0b540,0x0d6a0,0x0ada2,0x095b0,0x14977, 0x04970,0x0a4b0,0x0b4b5,0x06a50,0x06d40,0x1ab54,0x02b60,0x09570,0x052f2,0x04970, 0x06566,0x0d4a0,0x0ea50,0x06e95,0x05ad0,0x02b60,0x186e3,0x092e0,0x1c8d7,0
14、x0c950, 0x0d4a0,0x1d8a6,0x0b550,0x056a0,0x1a5b4,0x025d0,0x092d0,0x0d2b2,0x0a950,0x0b557, 0x06ca0,0x0b550,0x15355,0x04da0,0x0a5d0,0x14573,0x052d0,0x0a9a8,0x0e950,0x06aa0, 0x0aea6,0x0ab50,0x04b60,0x0aae4,0x0a570,0x05260,0x0f263,0x0d950,0x05b57,0x056a0, 0x096d0,0x04dd5,0x04ad0,0x0a4d0,0x0d4d4,0x0d250,0
15、x0d558,0x0b540,0x0b5a0,0x195a6, 0x095b0,0x049b0,0x0a974,0x0a4b0,0x0b27a,0x06a50,0x06d40,0x0af46,0x0ab60,0x09570, 0x04af5,0x04970,0x064b0,0x074a3,0x0ea50,0x06b58,0x055c0,0x0ab60,0x096d5,0x092e0, 0x0c960,0x0d954,0x0d4a0,0x0da50,0x07552,0x056a0,0x0abb7,0x025d0,0x092d0,0x0cab5, 0x0a950,0x0b4a0,0x0baa4,0
16、x0ad50,0x055d9,0x04ba0,0x0a5b0,0x15176,0x052b0,0x0a930, 0x07954,0x06aa0,0x0ad50,0x05b52,0x04b60,0x0a6e6,0x0a4e0,0x0d260,0x0ea65,0x0d530, 0x05aa0,0x076a3,0x096d0,0x04bd7,0x04ad0,0x0a4d0,0x1d0b6,0x0d250,0x0d520,0x0dd45, 0x0b5a0,0x056d0,0x055b2,0x049b0,0x0a577,0x0a4b0,0x0aa50,0x1b255,0x06d20,0x0ada0 ;/
17、判断闰年int IsLeapYear(int year) if(year%4=0 & year%100 !=0)|(year%400=0) return 1; return 0;/获取农历 y年的总天数int LunarYearDays(int y) int i, sum=348; for(i=0x8000; i0x8;=1) sum += (LunarInfoy-1900 & i)? 1: 0; return(sum+LunarLeapDays(y);/获取农历 y年闰月的天数int LunarLeapDays(int y) if(LunarLeapMonth(y) return(Lunar
18、Infoy-1900 & 0x10000)? 30: 29); else return(0);/获取农历 y年闰哪个月 1-12 , 没闰传回 0int LunarLeapMonth(int y) return(LunarInfoy-1900 & 0xf);/获取农历 y年m月的总天数int LunarMonthDays(int y,int m) return( (LunarInfoy-1900 & (0x10000m)?/ GetDayNumber.cpp int GetDayNumber(int year, int month, int day)int MonthDays12=0,31,2
19、8,31,30,31,30,31,31,30,31,30;int number=0;for(int i=0;i2) /该月不是1,2月份,这时需要考虑闰年 number=number+IsLeapYear(year);return number+day;/ GetTotalDayNumber.cpp /求从阳历1900年1月31日(阴历1900年1月1日)到某年某月某日(阳历)共多少天int GetTotalDayNumber(int year, int month, int day)for(int i=1900;year;i+) /1900年1月1日到year-1年12月31日的天数 if(IsLeapYear(i) number=number+366; number=number+365;number=number+Ge
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1