riqizhuanhuan.txt
来自「在网上载的一个日期转换代码,希望大家喜欢」· 文本 代码 · 共 935 行 · 第 1/3 页
TXT
935 行
{ 47, 0, 4, 50, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1 }, /* 1988 */
{ 36, 0, 6, 56, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0 },
{ 26, 5, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1 },
{ 45, 0, 1, 6, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0 },
{ 34, 0, 2, 11, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0 }, /* 1992 */
{ 22, 3, 4, 17, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0 },
{ 40, 0, 5, 22, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0 },
{ 30, 8, 6, 27, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1 },
{ 49, 0, 0, 32, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1 }, /* 1996 */
{ 37, 0, 2, 38, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1 },
{ 27, 5, 3, 43, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1 },
{ 46, 0, 4, 48, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1 },
{ 35, 0, 5, 53, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1 }, /* 2000 */
{ 23, 4, 0, 59, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 },
{ 42, 0, 1, 4, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 },
{ 31, 0, 2, 9, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0 },
{ 21, 2, 3, 14, 0, 1, 0, 1, 1, 0, 1, 0, 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0, 1, 0, 1, 0, 1, 0 },
{ 21, 2, 6, 54, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1 },
{ 40, 0, 0, 59, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1 }, /* 2024 */
{ 28, 6, 2, 5, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0 },
{ 47, 0, 3, 10, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1 },
{ 36, 0, 4, 15, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1 },
{ 25, 5, 5, 20, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0 }, /* 2028 */
{ 43, 0, 0, 26, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1 },
{ 32, 0, 1, 31, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0 },
{ 22, 3, 2, 36, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0 } };
#define lastyear (firstyear+sizeof(lunarcal)/sizeof(struct taglunarcal)-1)
/* 西历年每月之日数 */
int solarcal[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
/
Top
4 楼guanmj(雪在烧)回复于 2003-01-06 16:34:10 得分 0 * 西历年每月之累积日数, 平年与闰年 */
int solardays[2][14] = {
{ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365, 396 },
{ 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366, 397 } };
/* 求此西历年是否为闰年, 返回 0 为平年, 1 为闰年 */
int getleap( int year )
{
if ( year % 400 == 0 )
return 1;
else if ( year % 100 == 0 )
return 0;
else if ( year % 4 == 0 )
return 1;
else
return 0;
}
/* 西历农历转换 */
int calconv( struct convdate *cd )
{
int leap, d, sm, y, im, l1, l2, acc, i, lm, kc;
if ( cd->source == 0 ) /* solar */
{
if ( cd->solaryear <= firstyear || cd->solaryear > lastyear )
return 1;
sm = cd->solarmonth - 1;
if ( sm < 0 || sm > 11 )
return 2;
leap = getleap( cd->solaryear );
if ( sm == 1 )
d = leap + 28;
else
d = solarcal[sm];
if ( cd->solardate < 1 || cd->solardate > d )
return 3;
y = cd->solaryear - firstyear;
acc = solardays[leap][sm] + cd->solardate;
cd->weekday = ( acc + lunarcal[y].baseweekday ) % 7;
kc = acc + lunarcal[y].basekanchih;
cd->kan = kc % 10;
cd->chih = kc % 12;
if ( acc <= lunarcal[y].basedays )
{
y--;
cd->lunaryear = cd->solaryear - 1;
leap = getleap( cd->lunaryear );
sm += 12;
acc = solardays[leap][sm] + cd->solardate;
}
else
cd->lunaryear = cd->solaryear;
l1 = lunarcal[y].basedays;
for ( i=0; i<13; i++ )
{
l2 = l1 + lunarcal[y].monthdays[i] + 29;
if ( acc <= l2 )
break;
l1 = l2;
}
cd->lunarmonth = i + 1;
cd->lunardate = acc - l1;
im = lunarcal[y].intercalation;
if ( im != 0 && cd->lunarmonth > im )
{
cd->lunarmonth--;
if ( cd->lunarmonth == im )
cd->lunarmonth = -im;
}
if ( cd->lunarmonth > 12 )
cd->lunarmonth -= 12;
}
else /* lunar */
{
if ( cd->lunaryear < firstyear || cd->lunaryear >= lastyear )
return 1;
y = cd->lunaryear - firstyear;
im = lunarcal[y].intercalation;
lm = cd->lunarmonth;
if ( lm < 0 )
{
if ( lm != -im )
return 2;
}
else if ( lm < 1 || lm > 12 )
return 2;
if ( im != 0 )
{
if ( lm > im )
lm++;
else if ( lm == -im )
lm = im + 1;
}
lm--;
if ( cd->lunardate > lunarcal[y].monthdays[lm] + 29 )
return 3;
acc = lunarcal[y].basedays;
for ( i=0; i acc += lunarcal[y].monthdays[i] + 29;
acc += cd->lunardate;
leap = getleap( cd->lunaryear );
for ( i=13; i>=0; i-- )
if ( acc > solardays[leap][i] )
break;
cd->solardate = acc - solardays[leap][i];
if ( i <= 11 )
{
cd->solaryear = cd->lunaryear;
cd->solarmonth = i + 1;
}
else
{
cd->solaryear = cd->lunaryear + 1;
cd->solarmonth = i - 11;
}
leap = getleap( cd->solaryear );
y = cd->solaryear - firstyear;
acc = solardays[leap][cd->solarmonth-1] + cd->solardate;
cd->weekday = ( acc + lunarcal[y].baseweekday ) % 7;
kc = acc + lunarcal[y].basekanchih;
cd->kan = kc % 10;
cd->chih = kc % 12;
}
return 0;
}
Top
5 楼wyljery( VC Coder)回复于 2003-01-06 16:34:30 得分 0 //文件CalendarConvert.h
#ifndef __CALENDARCONVERT__H_
#define __CALENDARCONVERT__H_
typedef struct CalendarStruct
{
CalendarStruct(){}
CalendarStruct(int m_y,int m_m,int m_d)
{
FillThis(m_y,m_m,m_d);
}
int year;
int month;
int day;
int week;
BOOL isrunyue;
void FillThis(int m_y,int m_m,int m_d)
{
year=m_y;
month=m_m;
day=m_d;
}
void FromFile(CFile &m_file)
{
m_file.Read((char *)&year,sizeof(int));
m_file.Read((char *)&month,sizeof(int));
m_file.Read((char *)&day,sizeof(int));
}
void ToFile(CFile &m_file)
{
m_file.Write((char *)&year,sizeof(int));
m_file.Write((char *)&month,sizeof(int));
m_file.Write((char *)&day,sizeof(int));
}
}CALENDAR;
class CCalendarConvert
{
public:
CCalendarConvert();
~CCalendarConvert();
public:
CALENDAR ConvertToGongLi(CALENDAR m_nongli); //将农历日期转化为公历日期
CALENDAR ConvertToNongLi(CALENDAR m_gongli); //将公历日期转化为农历日期
int GetWeekInfo(CALENDAR m_gongli); //根据公历日期计算星期
void MakeCalendar(CALENDAR *m_cal,int y,int m,int d);//填充日期结构的年月日
BOOL GongDataIsValid(CALENDAR m_date); //判断公历日期是否在界内
BOOL NongDataIsValid(CALENDAR m_date); //判断农历日期是否在界内
int GetGongDays(CALENDAR m_start,CALENDAR m_end); //获取公历两个日期之间的天数
int GetNongDays(CALENDAR m_start,CALENDAR m_end); //获取农历两个日期之间的天数
int DaysFromNewYear(CALENDAR m_day); //公历日期到元旦的天数
CALENDAR CalGongDate(int year,int days); //根据天数(到元旦)计算公历日期
int CompareTwoDate(CALENDAR m_fir,CALENDAR m_sec); //比较两个日期的大小
CALENDAR GetCurGongDate(); //将当前公历日期合成为结构
CALENDAR GetDateAfterDays(CALENDAR m_first,int m_days);//当前公历日期后N天的公历日期
int GetNongRunYue(int year); //获取农历闰月
CString GetGanZhi(int m_nongyear); //获取农历年份的干支名称
void NongMonthToList(int m_nongyear,CComboBox & m_list);//将农历年的月份注入组合框
int GetGongMonthDays(int year,int month); //获取公历月的天数
int GetNongMonthDays(int year,int month); //获取农历月的天数
int GetNongMonthDays(int year,int month,BOOL m_run);//获取农历月的天数
int GetNongRunYueDays(int year); //获取农历年闰月天数
protected:
int GetGongYearDays(int year); //获取公历年的天数
int GetNongYearDays(int year); //获取农历年的天数
int DaysFromSpringDay(CALENDAR m_day); //农历日期到春节的天数
CALENDAR CalNongDate(int year,int days); //价格天数(到春节)计算农历日期
BOOL YearIsRunNian(int year); //公历年是否闰年
BOOL RunYueIsLarge(int year); //判断闰月是否为大月
BOOL MonthIsRunYue(int year,int month); //判断是否是闰月
BOOL NongMonthIsLarge(int year,int month); //判断农历年的月份是否为大月
BOOL GongMonthIsLarge(int month); //判断公历月份是否为大月(二月除外)
int GetDaysFromStart(int year); //农历大年初一到元旦的天数
int Cal2N(int n); //计算2的N次方
CString GetNNameIn60(int index); //获取60年中的第N年的天干地支名称
private:
int m_maxyear; //支持的最大年份
int m_minyear; //支持的最小年份
char **CalendarData; //公农历转化数据
};
#endif
// 测试代码
int main ()
{
time_t t1, t2;
struct tm tt;
DWORD dwDiffTime;
char sLunar[32];
tt.tm_year= 2000-1900;
tt.tm_mon=1;
tt.tm_mday=5;
tt.tm_hour=0;
tt.tm_min=0;
tt.tm_sec=0;
t1= mktime(&tt);
for (int i=0; i< 365; i++ ) {
tt.tm_year= 2050-1900;
tt.tm_mon=0;
tt.tm_mday=i;
tt.tm_hour=0;
tt.tm_min=0;
tt.tm_sec=0;
t2= mktime(&tt);
printf("%s", ctime(&t2));
dwDiffTime= difftime(t2,t1) / (60*60*24);
printf("起第 %d 天 ", dwDiffTime);
Lunar2Solar(sLunar, dwDiffTime);
puts(sLunar);
}
getch();
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?