我早些年已经用C++实现了转换库,并封装成了类似Com组件的DLL,经过近6年的维护,已经非常完善,如果需要的话,可以直接拿去用。如果是一般应用的日历,觉得直接查表就可以了,效率是最高的。至于你所说的用C有些许的性能提升,现在硬件性能已经非常不错了,你的些许是微秒级的甚至纳秒级的,根本感觉不到,手机的Android应用用JAVA开发都可以这么流畅,更何况在PC上呢。
typedef struct tagGDATE{
short sYear;//公历年
unsigned short wMonth;//公历月
unsigned short wDayOfWeek;//星期
unsigned short wDay;//公历日
}GDATE,*PGDATE,LPGDATE;//公历日期
typedef struct tagDATETIME{
short sYear;//公历年
unsigned short wMonth;//公历月
unsigned short wDayOfWeek;//星期
unsigned short wDay;//公历日
unsigned short wHour;//时
unsigned short wMinute;//分
unsigned short wSecond;//秒
unsigned short wMillisecond;//毫秒
}DATETIME,*PDATETIME,LPDATETIME;//公历时间
typedef struct tagLUNARMONTH{
short sYear;//农历所在的公历年份
unsigned short wMonth:7;//农历月(月名)
unsigned short wLeapMonth:1;//是否为闰月
unsigned short wDaysOfMonth:8;//农历月的总天数
short sFirstOrdinal;//农历月首的年内序数
}LUNARMONTH,*PLUNARMONTH,LPLUNARMONTH;//农历月份信息
typedef struct tagLDATE{
short sYear;//农历年
unsigned short wMonth:7;//农历月
unsigned short wLeapMonth:1;//闰月标志
unsigned short wDay:8;//农历日
unsigned short wDaysOfMonth:8;//月份总天数
unsigned short wDayofWeek:8;//星期
}LDATE,*PLDATE,LPLDATE;//农历日期
typedef struct tagEXTREMESEASON{
short sYear;//公历年份
short sYijiuOrdinal;//一九年内序数(二九至九九在此基础上推算可得到,故省略)
short sChufuOrdinal;//初伏年内序数
short sMofuOrdinal;//末伏(中伏在初伏后10天,故省略)
}EXTREMESEASON,*PEXTREMESEASON,LPEXTREMESEASON;//数九、三伏、入梅、出梅
typedef struct tagMEIYU{
short sYear;//公历年份
short sRumeiOrdinal;//入梅的年内序数
short sChumeiOrdinal;//出梅的年内序数
}MEIYU,*PMEIYU,LPMEIYU;//梅雨
typedef struct tagSOLARTERM{
short sYear;//公历年份
unsigned short wSTIndex;//当前节气编号。(立春编号为0)
short sSTOrdial;//节气的年内序数
unsigned short wSTHour;//时
unsigned short wSTMinute;//分
unsigned short wSTSecond;//秒
short sCalibration;//修正天数
}SOLARTERM,*PSOLARTERM,LPSOLARTERM;//节气
typedef struct tagLUNARPHASE{
short sYear;//公历年份
unsigned short wLPIndex;//月相(0:朔,1:上弦,2:望,3:下弦)
short sLPOrdinal;//年内序数
unsigned short wLPHour;//时
unsigned short wLPMinute;//分
unsigned short wLPSecond;//秒
}LUNARPHASE,*PLUNARPHASE,LPLUNARPHASE;//月相
typedef struct tagSHERI{
short sYear;//公历年份
short sChunSheOrdinal;//指定年份的春社日的年内序数
short sQiuSheOrdinal;//指定年份的秋社日的年内序数
}SHERI,*PSHERI,LPSHERI;//社日
struct _GanzhiElement
{
unsigned short wTiangan;//天干
unsigned short wDizhi;//地支
};//干支元素
typedef struct tagSIZHU{
struct _GanzhiElement gzYear;//年柱
struct _GanzhiElement gzMonth;//月柱
struct _GanzhiElement gzDay;//日柱
struct _GanzhiElement gzHour;//时柱
}SIZHU,*PSIZHU,LPSIZHU;//四柱
class CLunar
{
public:
virtual bool GetDayOrdinal(GDATE DateG,short sYear,short & sDays)=0;
virtual bool GetDateFromOrdinal(short sYear,short sDays,GDATE & DateG)=0;
virtual bool GetConstellation(GDATE DateG,unsigned short & wConstellationIndex)=0;
virtual bool GetSiZhu(DATETIME Datetime,SIZHU & SiZhu,bool bYStartLiChun=false)=0;
virtual bool LDateToGDate(LDATE DateL,GDATE & DateG)=0;
virtual bool GDateToLDate(GDATE DateG,LDATE & DateL)=0;
virtual bool GetFirstMonthInfo(short sYear,LUNARMONTH & MonthInfo)=0;
virtual bool GetNextMonthInfo(LUNARMONTH & MonthInfo)=0;
virtual bool GetPreviousMonthInfo(LUNARMONTH & MonthInfo)=0;
virtual bool GetMonthInfoByIndex(short sYear,unsigned short wMIIndex,LUNARMONTH & MonthInfo)=0;
virtual bool GetFirstLunarPhase(short sYear,unsigned short wMonth,LUNARPHASE & LunarPhase)=0;
virtual bool GetNextLunarPhase(LUNARPHASE & LunarPhase)=0;
virtual bool GetPreviousLunarPhase(LUNARPHASE & LunarPhase)=0;
virtual bool GetFirstSolarTerm(short sYear,SOLARTERM & SolarTerm)=0;
virtual bool GetNextSolarTerm(SOLARTERM & SolarTerm)=0;
virtual bool GetPreviousSolarTerm(SOLARTERM & SolarTerm)=0;
virtual bool GetSolarTermByIndex(short sYear,unsigned short wSTIndex,SOLARTERM & SolarTerm)=0;
virtual bool IsLeapYear(short sYear,bool & bLeapYear)=0;
virtual bool GetExtremeSeason(short sYear,EXTREMESEASON & ExtremeSeason)=0;
virtual bool GetMeiYu(short sYear,MEIYU & Meiyu)=0;
virtual bool GetSheRi(short sYear,SHERI & SheRi)=0;
virtual bool GetDays(GDATE DateG1,GDATE DateG2,long & lDays)=0;
virtual bool GetDaysEx(DATETIME Datetime1,DATETIME Datetime2,double & dDays)=0;
virtual bool GetDate(GDATE DateG,long lDays,GDATE & DstDateG)=0;
virtual bool GetDateEx(DATETIME Datetime,double dDays,DATETIME & DstDatetime)=0;
virtual bool InitDate(GDATE & DateG,bool bCurrentTime,short sYear=0,unsigned short wMonth=1,unsigned short wDay=1)=0;
virtual bool InitDateTime(DATETIME & Datetime,bool bCurrentTime,short sYear=0,unsigned short wMonth=1,unsigned short wDay=1,unsigned short wHour=0,unsigned short wMinute=0,unsigned short wSecond=0,unsigned short wMilliSecond=0)=0;
virtual bool GetDayOfWeek(short sYear,unsigned short wMonth,unsigned short wDay,unsigned short & wDayOfWeek)=0;
virtual bool GetEmperorReign(GDATE DateG,char * pBuffer,unsigned int uBufSize)=0;
virtual GDATE InitDateFromDateTime(DATETIME Datetime)=0;
virtual DATETIME InitDatetimeFromDate(GDATE DateG)=0;
virtual unsigned short GetDaysOfMonth(short sYear,unsigned short wMonth)=0;
virtual unsigned short GetDaysOfYear(short sYear)=0;
virtual unsigned short GetLeapMonth(short sYear)=0;
virtual unsigned short GetDaysOfLunarMonth(short sYear,unsigned short wLunarMonth,bool bLeapMonth)=0;
virtual unsigned short GetDaysOfLunarYear(short sYear)=0;
virtual long Release(void)=0;
protected:
CLunar(void);
virtual ~CLunar(void);
};
[此贴子已经被作者于2016-5-16 16:24:12编辑过]