农历天干地支算法源代码大全
(javascript、vbscript、C#、flash、C++、C等等)
WonSoft编
文章提供计算农历天干地支及当年属相的算法源程序,使用的语言为Javascript、VBScript、C#等。
一、C# 代码(1):
原来还准备自己写算法,并研究农历规则。发现那太难和麻烦了,光是农历的推算那就我等专门研究历法的人一下搞懂的。后来发现。NET类库也提供一些基础的农历类System.Globalization.ChineseLunisolarCalendar。我改装了一下如DateTime时间形式。代码如下。实现了 公历农历转换的功能。但是只能算到1900~2100年之间的。基本够日常使用了。源代码如下:
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace System
- {
-
-
-
-
- class ChinaDateTime
- {
- private int year, month, dayOfMonth;
- private bool isLeap;
- public DateTime time;
-
-
-
- public int Year
- {
- get { return year; }
- }
-
-
-
- public int Month
- {
- get { return month; }
- }
-
-
-
- public int DayOfMonth
- {
- get { return dayOfMonth; }
- }
-
-
-
- public bool IsLeap
- {
- get { return isLeap; }
- }
- System.Globalization.ChineseLunisolarCalendar cc;
-
-
-
-
- public ChinaDateTime(DateTime time)
- {
- cc = new System.Globalization.ChineseLunisolarCalendar();
-
- if (time > cc.MaxSupportedDateTime || time < cc.MinSupportedDateTime)
- throw new Exception("参数日期时间不在支持的范围内,支持范围:" + cc.MinSupportedDateTime.ToShortDateString()+"到"+cc.MaxSupportedDateTime.ToShortDateString());
- year = cc.GetYear(time);
- month = cc.GetMonth(time);
- dayOfMonth = cc.GetDayOfMonth(time);
- isLeap = cc.IsLeapMonth(year, month);
- if (isLeap) month -= 1;
- this.time = time;
- }
-
-
-
- public static ChinaDateTime Now
- {
- get { return new ChinaDateTime(DateTime.Now); }
- }
-
-
-
-
-
-
-
- public ChinaDateTime(int Year, int Month, int DayOfMonth, bool IsLeap)
- {
- if (Year >= cc.MaxSupportedDateTime.Year || Year <= cc.MinSupportedDateTime.Year)
- throw new Exception("参数年份时间不在支持的范围内,支持范围:" + cc.MinSupportedDateTime.ToShortDateString() + "到" + cc.MaxSupportedDateTime.ToShortDateString());
- if (Month < 1 || Month > 12)
- throw new Exception("月份必须在1~12范围");
- cc = new System.Globalization.ChineseLunisolarCalendar();
-
- if(cc.GetLeapMonth(Year)!=Month&&IsLeap)
- throw new Exception("指定的月份不是当年的闰月");
- if (cc.GetDaysInMonth(Year, IsLeap ? Month + 1 : Month) < DayOfMonth || DayOfMonth < 1)
- throw new Exception("指定的月中的天数不在当前月天数有效范围");
- year = Year;
- month = Month;
- dayOfMonth = DayOfMonth;
- isLeap = IsLeap;
- time = DateTime.Now;
- }
-
-
-
- public DateTime ToDateTime()
- {
- return cc.ToDateTime(year, isLeap ? month + 1 : month, dayOfMonth, time.Hour, time.Minute, time.Second, time.Millisecond);
- }
-
-
-
-
-
- public static DateTime ToDateTime(ChinaDateTime CnTime)
- {
- return CnTime.ToDateTime();
- }
-
-
-
-
-
- public static ChinaDateTime ToChinaDateTime(DateTime Time)
- {
- return new ChinaDateTime(Time);
- }
- }
- }
二、C#代码(2):
1、农历类的使用
.net框架不支持直接将日期转换成农历格式的字符串,那么要将显示农历格式的日期,就只要自已写代码了。不过由于已经有了ChineseLunisolarCalendar类实现了公历转换为农历日期的功能,所以要写这样的代码也比较简单。需要用到ChineseLunisolarCalendar以下几个主要方法:
int GetYear (DateTime time) 获取指定公历日期的农历年份,使用的还是公历纪元。在每年的元旦之后春节之前农历的纪年会比公历小1,其它时候等于公历纪年。虽然农历使用传说中的耶稣生日纪元似乎不太妥当,不过我们确实已经几十年没有实行一个更好的纪年办法,也只有将就了。
int GetMonth (DateTime time) 获取指定公历日期的农历月份。这里要注意了,由于农历有接近三分之一的年份存在闰月,则在这些年份里会有十三个,而具体哪一个月是闰月也说不准,这里不同于希伯来历。以今年为例,今年闰七月,则此方法在参数为闰七月的日期是返回值为 8,参数为农历十二月的日期时返回值为13
bool IsLeapMonth ( int year, int month) 获取指定农历年份和月份是否为闰月,这个函数和上个函数配合使用就可以算出农历的月份了。
int GetDayOfMonth (DateTime time) 获取指定公历日期的农历天数,这个值根据大月或者小月取值是1到30或者1到29, MSDN上说的1到31显然是错的, 没有哪个农历月份会有31天。
int GetSexagenaryYear (DateTime time) 获取指定公历日期的农历年份的干支纪年,从1到60,分别是甲子、乙丑、丙寅、….癸亥, 比如戊戌变法、辛亥革命就是按这个来命名的。当然算八字也少不了这个。
int GetCelestialStem (int sexagenaryYear) 获取一个天支的天干, 从1到10, 表示甲、乙、丙….,说白了就是对10取模。
int GetTerrestrialBranch (int sexagenaryYear) ) 获取一个干支的地支,, 从1到12, 表示子、丑、寅、…今年是狗年,那么今年年份的地支就是“戌”。
有了这几个方法,显示某天的农历月份日期、农历节日等都是小菜一碟,算命先生排八字用这几个方法,又快又准确,写出的代码也很短。
2、几种东亚农历类的区别
经过我的测试,ChineseLunisolarCalendar, JapaneseLunisolarCalendar, KoreanLunisolaCalendarr, TaiwanLunisolarCalendar这四种日历,无论哪一种,以2006年2月6日为参数,调用它们的GetMonth方法得到的结果都是1,GetDayOfMonth得到的结果都是8。想想也是,我们过的端午节和韩国的不太可能不是一天。
但是调用GetYear方法得到结果就有区别了ChineseLunisolarCalendar和KoreanLunisolarCalendar都返回2006,也就是公历纪年,TaiwanLunisolarCalendar的返回值是95,依然是民国纪年,JapaneseLunisolarCalendar的返回值是18, 平成纪年。
另外的一个区别是这四种日历的MinSupportedDateTime和MaxSupportedDateTime各不一样,以下是对照表:
日历类 |
MinSupportedDateTime |
MaxSupportedDateTime |
ChineseLunisolarCalendar |
公元1901年1月初1 |
公元2100年12月29 |
TaiwanLunisolarCalendar |
民国1年1月初1 |
民国139年12月29 |
JapaneseLunisolarCalendar |
昭和35年1月初1 |
平成61年12月29 |
KoreanLunisolarCalendar |
公元918年1月初1 |
公元2050年12月29 |
韩国农历类支持的最小日期为918年(也即高丽王朝建立的年份),以此而论,中国农历类支持的最小日期不说从商周算起,从汉唐算总该没问题吧?微软公司啊,又在“厚彼薄此”,唉。
其次,日本还以天皇纪年,如果哪天xxxx, 岂不是使用JapaneseLunisolarCalendar写出的程序都有问题啦?
3、写自已的日期格式化器
昨天看了一篇文章,说目前大家用的“农历”这个术语是文革时期才有的,目的是反封建。这里为了省事,还是继续使用这个术语。而英文名称ChineseLunisolarCalendar太长,我自己的代码中就用ChineseCalendar为相关功能命名,这个名字也还过得去吧。
我原先设想自定义一个类,使得能写出这样的代码:
string s= DateTime.Now.ToString(new MyFormatProvider());
就能得出我想要的农历日期字符串,经过测试却失败了,依据我的分析,微软公司在.net框架中把日期时间型的格式写死了,只能依据相关的地区采用固定的几种显示格式,没法再自行定义。而前文已经说过,而所有的相关格式微软公司都放到一个名为culture.nlp的文件中(这个文件在以前的.net框架是一个独立的文件,在.net 2.0被作为一个资源编译到mscorlib.dll中。) (我的这个不能为DateTime写自已的格式化器的观点没有资料佐证,如有不当之处,请大家指正)
虽然不能为DataTime写自定义的格式器,但还有另外一个途径,就是为String类的Format方法写自定义格式化器,我测试了一下,效果还不错,调用方式如下:
string s= String.Format(new ChineseCalendarFormatter(), "{0:D}",DateTime.Now);
可以得到“二〇〇六年正月初九”
string s= String.Format(new ChineseCalendarFormatter(), "{0:d}",DateTime.Now);
可以得到“丙戌年正月初九”
虽然没有前面所设想的方便,但也还能接受,全部代码帖出如下:
第一个类,主要是封装了农历的一些常用字符和对日历处理的最基本功能
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Globalization;
- public static class ChineseCalendarHelper
- {
- public static string GetYear(DateTime time)
- {
- StringBuilder sb = new StringBuilder();
- int year = calendar.GetYear(time);
- int d;
- do
- {
- d = year % 10;
- sb.Insert(0, ChineseNumber[d]);
- year = year / 10;
- } while (year > 0);
- return sb.ToString();
- }
- public static string GetMonth(DateTime time)
- {
- int month = calendar.GetMonth(time);
- int year = calendar.GetYear(time);
- int leap = 0;
-
- for (int i = 3; i <= month; i++)
- {
- if (calendar.IsLeapMonth(year, i))
- {
- leap = i;
- break;
- }
- }
- if (leap > 0) month--;
- return (leap == month + 1 ? "闰" : "") + ChineseMonthName[month - 1];
- }
- public static string GetDay(DateTime time)
- {
- return ChineseDayName[calendar.GetDayOfMonth(time) - 1];
- }
- public static string GetStemBranch(DateTime time)
- {
- int sexagenaryYear = calendar.GetSexagenaryYear(time);
- string stemBranch = CelestialStem.Substring(sexagenaryYear % 10 - 1, 1) +
- TerrestrialBranch.Substring(sexagenaryYear % 12 - 1, 1);
- return stemBranch;
- }
- private static ChineseLunisolarCalendar calendar = new ChineseLunisolarCalendar();
- private static string ChineseNumber = "〇一二三四五六七八九";
- public const string CelestialStem = "甲乙丙丁戊己庚辛壬癸";
- public const string TerrestrialBranch = "子丑寅卯辰巳午未申酉戌亥";
- public static readonly string[] ChineseDayName = new string[] {
- "初一","初二","初三","初四","初五","初六","初七","初八","初九","初十",
- "十一","十二","十三","十四","十五","十六","十七","十八","十九","二十",
- "廿一","廿二","廿三","廿四","廿五","廿六","廿七","廿八","廿九","三十"};
- public static readonly string[] ChineseMonthName = new string[]
- { "正", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二" };
- }
第二个类为自定义格式化器:
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Globalization;
- using System.Threading;
- public class ChineseCalendarFormatter : IFormatProvider, ICustomFormatter
- {
-
- public object GetFormat(Type formatType)
- {
- if (formatType == typeof(ICustomFormatter))
- return this;
- else
- return Thread.CurrentThread.CurrentCulture.GetFormat(formatType);
- }
-
- public string Format(string format, object arg, IFormatProvider formatProvider)
- {
- string s;
- IFormattable formattable = arg as IFormattable;
- if (formattable == null)
- s = arg.ToString();
- else
- s = formattable.ToString(format, formatProvider);
- if (arg.GetType() == typeof(DateTime))
- {
- DateTime time = (DateTime)arg;
- switch (format)
- {
- case "D":
- s = String.Format("{0}年{1}月{2}",
- ChineseCalendarHelper.GetYear(time),
- ChineseCalendarHelper.GetMonth(time),
- ChineseCalendarHelper.GetDay(time));
- break;
- case "d":
- s = String.Format("{0}年{1}月{2}", ChineseCalendarHelper.GetStemBranch(time),
- ChineseCalendarHelper.GetMonth(time),
- ChineseCalendarHelper.GetDay(time));
- break;
- case "M":
- s = String.Format("{0}月{1}", ChineseCalendarHelper.GetMonth(time),
- ChineseCalendarHelper.GetDay(time));
- break;
- case "Y":
- s = String.Format("{0}年{1}月", ChineseCalendarHelper.GetYear(time),
- ChineseCalendarHelper.GetMonth(time));
- break;
- default:
- s = String.Format("{0}年{1}月{2}", ChineseCalendarHelper.GetYear(time),
- ChineseCalendarHelper.GetMonth(time),
- ChineseCalendarHelper.GetDay(time));
- break;
- }
- }
- return s;
- }
- }
这段代码中间处理格式那部份稍做改进,就可以支持更多的日期格式。
有了这两段代码为原型,要实现计算和显示一个日期的农历日期及其它功能,基本上就很容易了。
三、VBScript 代码:
- <%
- 'Wonsoft, Welcome to visit my web http://wonsoft.cn
- '***********************************************
- ' 类名称:ChinaDay
- ' 用途:
- ' 根据输入的日期计算该日期的农历天干地支及当年属相
- ' 使用方法:
- ' 第一个参数为输入参数,不填写默认为当日,
- ' 只计算1921-2-8之后的日期
- ' ##-------------------------------------------##
- ' Dim objChinaDay
- ' Dim sDay, sWeekDay, sChinaDay, sChinaYear,sChinaAni
- ' Set objChinaDay = New ChinaDay
- ' Call objChinaDay.Action("",sDay,sWeekDay,sChinaYear,sChinaDay,sChinaAni)
- ' Response.Write sDay&"<BR>"
- ' Response.Write sWeekDay&"<BR>"
- ' Response.Write sChinaYear&"<BR>"
- ' Response.Write sChinaDay&"<BR>"
- ' Response.Write sChinaAni&"<BR>"
- ' ##-------------------------------------------##
- ' Copyright: 本代码非原创,是2001年收集的,原作者未知。
- ' License:Free
- '*******************************************************
- Class ChinaDay
- Dim arrWeekName(7), MonthAdd(11), NongliData(99)
- Dim arrTianGan(9), arrDiZhi(11), arrShuXiang(11), arrDayName(30), arrMonName(12)
- Dim curTime, curYear, curMonth, curDay, curWeekday
- Dim i, m, n, k, isEnd, bit, TheDate
- '初始化数据
- Sub Class_Initialize()
- '---------------------------------------------------
- '定义显示字串
- '星期名
- arrWeekName(0) = "*"
- arrWeekName(1) = "星期日"
- arrWeekName(2) = "星期一"
- arrWeekName(3) = "星期二"
- arrWeekName(4) = "星期三"
- arrWeekName(5) = "星期四"
- arrWeekName(6) = "星期五"
- arrWeekName(7) = "星期六"
- '天干名称
- arrTianGan(0) = "甲"
- arrTianGan(1) = "乙"
- arrTianGan(2) = "丙"
- arrTianGan(3) = "丁"
- arrTianGan(4) = "戊"
- arrTianGan(5) = "己"
- arrTianGan(6) = "庚"
- arrTianGan(7) = "辛"
- arrTianGan(8) = "壬"
- arrTianGan(9) = "癸"
- '地支名称
- arrDiZhi(0) = "子"
- arrDiZhi(1) = "丑"
- arrDiZhi(2) = "寅"
- arrDiZhi(3) = "卯"
- arrDiZhi(4) = "辰"
- arrDiZhi(5) = "巳"
- arrDiZhi(6) = "午"
- arrDiZhi(7) = "未"
- arrDiZhi(8) = "申"
- arrDiZhi(9) = "酉"
- arrDiZhi(10) = "戌"
- arrDiZhi(11) = "亥"
- '属相名称
- arrShuXiang(0) = "鼠"
- arrShuXiang(1) = "牛"
- arrShuXiang(2) = "虎"
- arrShuXiang(3) = "兔"
- arrShuXiang(4) = "龙"
- arrShuXiang(5) = "蛇"
- arrShuXiang(6) = "马"
- arrShuXiang(7) = "羊"
- arrShuXiang(8) = "猴"
- arrShuXiang(9) = "鸡"
- arrShuXiang(10) = "狗"
- arrShuXiang(11) = "猪"
- '农历日期名
- arrDayName(0) = "*"
- arrDayName(1) = "初一"
- arrDayName(2) = "初二"
- arrDayName(3) = "初三"
- arrDayName(4) = "初四"
- arrDayName(5) = "初五"
- arrDayName(6) = "初六"
- arrDayName(7) = "初七"
- arrDayName(8) = "初八"
- arrDayName(9) = "初九"
- arrDayName(10) = "初十"
- arrDayName(11) = "十一"
- arrDayName(12) = "十二"
- arrDayName(13) = "十三"
- arrDayName(14) = "十四"
- arrDayName(15) = "十五"
- arrDayName(16) = "十六"
- arrDayName(17) = "十七"
- arrDayName(18) = "十八"
- arrDayName(19) = "十九"
- arrDayName(20) = "二十"
- arrDayName(21) = "廿一"
- arrDayName(22) = "廿二"
- arrDayName(23) = "廿三"
- arrDayName(24) = "廿四"
- arrDayName(25) = "廿五"
- arrDayName(26) = "廿六"
- arrDayName(27) = "廿七"
- arrDayName(28) = "廿八"
- arrDayName(29) = "廿九"
- arrDayName(30) = "三十"
- '农历月份名
- arrMonName(0) = "*"
- arrMonName(1) = "正"
- arrMonName(2) = "二"
- arrMonName(3) = "三"
- arrMonName(4) = "四"
- arrMonName(5) = "五"
- arrMonName(6) = "六"
- arrMonName(7) = "七"
- arrMonName(8) = "八"
- arrMonName(9) = "九"
- arrMonName(10) = "十"
- arrMonName(11) = "十一"
- arrMonName(12) = "腊"
- '---------------------------------------------------------
- '公差数据定义
- '公历每月前面的天数
- MonthAdd(0) = 0
- MonthAdd(1) = 31
- MonthAdd(2) = 59
- MonthAdd(3) = 90
- MonthAdd(4) = 120
- MonthAdd(5) = 151
- MonthAdd(6) = 181
- MonthAdd(7) = 212
- MonthAdd(8) = 243
- MonthAdd(9) = 273
- MonthAdd(10) = 304
- MonthAdd(11) = 334
- '农历数据
- NongliData(0) = 2635
- NongliData(1) = 333387
- NongliData(2) = 1701
- NongliData(3) = 1748
- NongliData(4) = 267701
- NongliData(5) = 694
- NongliData(6) = 2391
- NongliData(7) = 133423
- NongliData(8) = 1175
- NongliData(9) = 396438
- NongliData(10) = 3402
- NongliData(11) = 3749
- NongliData(12) = 331177
- NongliData(13) = 1453
- NongliData(14) = 694
- NongliData(15) = 201326
- NongliData(16) = 2350
- NongliData(17) = 465197
- NongliData(18) = 3221
- NongliData(19) = 3402
- NongliData(20) = 400202
- NongliData(21) = 2901
- NongliData(22) = 1386
- NongliData(23) = 267611
- NongliData(24) = 605
- NongliData(25) = 2349
- NongliData(26) = 137515
- NongliData(27) = 2709
- NongliData(28) = 464533
- NongliData(29) = 1738
- NongliData(30) = 2901
- NongliData(31) = 330421
- NongliData(32) = 1242
- NongliData(33) = 2651
- NongliData(34) = 199255
- NongliData(35) = 1323
- NongliData(36) = 529706
- NongliData(37) = 3733
- NongliData(38) = 1706
- NongliData(39) = 398762
- NongliData(40) = 2741
- NongliData(41) = 1206
- NongliData(42) = 267438
- NongliData(43) = 2647
- NongliData(44) = 1318
- NongliData(45) = 204070
- NongliData(46) = 3477
- NongliData(47) = 461653
- NongliData(48) = 1386
- NongliData(49) = 2413
- NongliData(50) = 330077
- NongliData(51) = 1197
- NongliData(52) = 2637
- NongliData(53) = 268877
- NongliData(54) = 3365
- NongliData(55) = 531109
- NongliData(56) = 2900
- NongliData(57) = 2922
- NongliData(58) = 398042
- NongliData(59) = 2395
- NongliData(60) = 1179
- NongliData(61) = 267415
- NongliData(62) = 2635
- NongliData(63) = 661067
- NongliData(64) = 1701
- NongliData(65) = 1748
- NongliData(66) = 398772
- NongliData(67) = 2742
- NongliData(68) = 2391
- NongliData(69) = 330031
- NongliData(70) = 1175
- NongliData(71) = 1611
- NongliData(72) = 200010
- NongliData(73) = 3749
- NongliData(74) = 527717
- NongliData(75) = 1452
- NongliData(76) = 2742
- NongliData(77) = 332397
- NongliData(78) = 2350
- NongliData(79) = 3222
- NongliData(80) = 268949
- NongliData(81) = 3402
- NongliData(82) = 3493
- NongliData(83) = 133973
- NongliData(84) = 1386
- NongliData(85) = 464219
- NongliData(86) = 605
- NongliData(87) = 2349
- NongliData(88) = 334123
- NongliData(89) = 2709
- NongliData(90) = 2890
- NongliData(91) = 267946
- NongliData(92) = 2773
- NongliData(93) = 592565
- NongliData(94) = 1210
- NongliData(95) = 2651
- NongliData(96) = 395863
- NongliData(97) = 1323
- NongliData(98) = 2707
- NongliData(99) = 265877
- End Sub
- '############################################################
- '主要方法 Action
- ' inDay 输入日期,如果不输入则默认为当前日期
- ' sDay 中文格式日期
- ' sWeekDay 周几
- ' sChinaYear 农历年
- ' sChinaDay 农历日
- ' sChinaAni 属相
- '############################################################
- Public Function Action(inDay,sDay,sWeekDay,sChinaYear,sChinaDay,sChinaAni)
- '转换要转换的日期
- If inDay="" Or Not IsDate(inDay) Then
- '获取当前系统时间
- curTime = Now()
- Else
- curTime = CDate(inDay)
- End If
- If Datediff("d",curTime,Cdate("1921-2-8"))>0 Then
- Exit Function
- End If
- '生成当前公历年、月、日 ==> sDay
- curYear = Year(curTime)
- curMonth = Month(curTime)
- curDay = Day(curTime)
- sDay = curYear&"年"
- If (curMonth < 10) Then
- sDaysDay = sDay&"0"&curMonth&"月"
- Else
- sDaysDay = sDay&curMonth&"月"
- End If
- If (curDay < 10) Then
- sDaysDay = sDay&"0"&curDay&"日"
- Else
- sDaysDay = sDay&curDay&"日"
- End If
- '生成当前公历星期 ==> sWeekDay
- curWeekday = Weekday(curTime)
- sWeekDay = arrWeekName(curWeekday)
- '计算到初始时间1921年2月8日的天数:1921-2-8(正月初一)
- TheDate = (curYear - 1921) * 365 + Int((curYear - 1921) / 4) + curDay + MonthAdd(curMonth - 1) - 38
- If ((curYear Mod 4) = 0 AND curMonth > 2) Then
- TheDateTheDate = TheDate + 1
- End If
- '计算农历天干、地支、月、日
- isEnd = 0
- m = 0
- '------------------------------------
- Do
- If (NongliData(m) < 4095) Then
- k = 11
- Else
- k = 12
- End if
- n = k
- '------------------------------------
- Do
- If (n < 0) Then
- Exit Do
- End If
- '获取NongliData(m)的第n个二进制位的值
- bit = NongliData(m)
- For i = 1 To n Step 1
- bit = Int(bit / 2)
- Next
- bitbit = bit Mod 2
- If (TheDate <= 29 + bit) Then
- isEnd = 1
- Exit Do
- End If
- TheDateTheDate = TheDate - 29 - bit
- nn = n - 1
- Loop
- '------------------------------------
- If (isEnd = 1) Then
- Exit Do
- End If
- mm = m + 1
- Loop
- '------------------------------------
- curYear = 1921 + m
- curMonth = k - n + 1
- curDay = TheDate
- If (k = 12) Then
- If (curMonth = (Int(NongliData(m) / 65536) + 1)) Then
- curMonth = 1 - curMonth
- ElseIf (curMonth > (Int(NongliData(m) / 65536) + 1)) Then
- curMonthcurMonth = curMonth - 1
- End if
- End If
- '生成农历天干、地支==> sChinaYear
- sChinaYear = "农历"&arrTianGan(((curYear - 4) Mod 60) Mod 10)&arrDiZhi(((curYear - 4) Mod 60) Mod 12)&"年"
- '生成属相 == > sChinaAni
- sChinaAni = arrShuXiang(((curYear - 4) Mod 60) Mod 12)
- '生成农历月、日 ==> NongliDayStr
- If (curMonth < 1) Then
- sChinaDay = "闰"&arrMonName(-1 * curMonth)
- Else
- sChinaDay = arrMonName(curMonth)
- End If
- sChinaDaysChinaDay = sChinaDay&"月"
- sChinaDaysChinaDay = sChinaDay & arrDayName(curDay)
- End Function
- End Class
- %>
四、JavaScript 代码:
- <SCRIPT language=JavaScript>
上面的代码不支持Firefox,请使用查找、替换,把getYear()修改为getFullYear()就可以支持firefox了。
五、Flash代码:
农历FLASH源码、旧历FLASH日历、旧历FLASH时钟
在FLASH中,制作时钟、日历都不难。在网上搜索一下,也会有一大遍源码等着你去下载。但不知是我孤陋寡闻,还是咋地。在网上还没见过农历的代码,在民族文化如此繁荣的中国。竟然没有人来研究这个。实在是有点遗憾。花点时间,研究了一下。随后把源码附上。希望大家共同讨论。其中难的就是闰月部分。
点击播放/隐藏媒体:http://www.taoshaw.com/taoshaw/study/jilishizhong/Taoshaw_Time.swf
制作过程,前面的就不说了。直接发代码吧。
新建一倒计时类"Taoshaw_data.as"。
然后输入如下代码:
- class Taoshaw_data extends Date {
-
-
-
-
-
- private var tao_txtnum_info = new Array(0x4bd8, 0x4ae0, 0xa570, 0x54d5, 0xd260, 0xd950, 0x5554, 0x56af, 0x9ad0, 0x55d2, 0x4ae0, 0xa5b6, 0xa4d0, 0xd250, 0xd255, 0xb54f, 0xd6a0, 0xada2, 0x95b0, 0x4977, 0x497f, 0xa4b0, 0xb4b5, 0x6a50, 0x6d40, 0xab54, 0x2b6f, 0x9570, 0x52f2, 0x4970, 0x6566, 0xd4a0, 0xea50, 0x6a95, 0x5adf, 0x2b60, 0x86e3, 0x92ef, 0xc8d7, 0xc95f, 0xd4a0, 0xd8a6, 0xb55f, 0x56a0, 0xa5b4, 0x25df, 0x92d0, 0xd2b2, 0xa950, 0xb557, 0x6ca0, 0xb550, 0x5355, 0x4daf, 0xa5b0, 0x4573, 0x52bf, 0xa9a8, 0xe950, 0x6aa0, 0xaea6, 0xab50, 0x4b60, 0xaae4, 0xa570, 0x5260, 0xf263, 0xd950, 0x5b57, 0x56a0, 0x96d0, 0x4dd5, 0x4ad0, 0xa4d0, 0xd4d4, 0xd250, 0xd558, 0xb540, 0xb6a0, 0x95a6, 0x95bf, 0x49b0, 0xa974, 0xa4b0, 0xb27a, 0x6a50, 0x6d40, 0xaf46, 0xab60, 0x9570, 0x4af5, 0x4970, 0x64b0, 0x74a3, 0xea50, 0x6b58, 0x5ac0, 0xab60, 0x96d5, 0x92e0, 0xc960, 0xd954, 0xd4a0, 0xda50, 0x7552, 0x56a0, 0xabb7, 0x25d0, 0x92d0, 0xcab5, 0xa950, 0xb4a0, 0xbaa4, 0xad50, 0x55d9, 0x4ba0, 0xa5b0, 0x5176, 0x52bf, 0xa930, 0x7954, 0x6aa0, 0xad50, 0x5b52, 0x4b60, 0xa6e6, 0xa4e0, 0xd260, 0xea65, 0xd530, 0x5aa0, 0x76a3, 0x96d0, 0x4afb, 0x4ad0, 0xa4d0, 0xd0b6, 0xd25f, 0xd520, 0xdd45, 0xb5a0, 0x56d0, 0x55b2, 0x49b0, 0xa577, 0xa4b0, 0xaa50, 0xb255, 0x6d2f, 0xada0, 0x4b63, 0x937f, 0x49f8, 0x4970, 0x64b0, 0x68a6, 0xea5f, 0x6b20, 0xa6c4, 0xaaef, 0x92e0, 0xd2e3, 0xc960, 0xd557, 0xd4a0, 0xda50, 0x5d55, 0x56a0, 0xa6d0, 0x55d4, 0x52d0, 0xa9b8, 0xa950, 0xb4a0, 0xb6a6, 0xad50, 0x55a0, 0xaba4, 0xa5b0, 0x52b0, 0xb273, 0x6930, 0x7337, 0x6aa0, 0xad50, 0x4b55, 0x4b6f, 0xa570, 0x54e4, 0xd260, 0xe968, 0xd520, 0xdaa0, 0x6aa6, 0x56df, 0x4ae0, 0xa9d4, 0xa4d0, 0xd150, 0xf252, 0xd520);
- private var tao_txtsolarMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
-
- private var Gan = new Array("甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸");
- private var Zhi = new Array("子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥");
- private var Animals = new Array("鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪");
-
- private var tao_txtsolarTerm = new Array("小寒", "大寒", "立春", "雨水", "惊蛰", "春分", "清明", "谷雨", "立夏", "小满", "芒种", "夏至", "小暑", "大暑", "立秋", "处暑", "白露", "秋分", "寒露", "霜降", "立冬", "小雪", "大雪", "冬至");
- private var tao_txtsTermInfo = new Array(0, 21208, 42467, 63836, 85337, 107014, 128867, 150921, 173149, 195551, 218072, 240693, 263343, 285989, 308563, 331033, 353350, 375494, 397447, 419210, 440795, 462224, 483532, 504758);
- private var nStr1 = new Array('日', '一', '二', '三', '四', '五', '六', '七', '八', '九', '十');
- private var nStr2 = new Array('初', '十', '廿', '卅', '□');
- private var monthName = new Array("JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC");
- private var cyear:Number;
- private var cmonth:Number;
- private var cday:Number;
- private var isLeap:Boolean;
- private var nianzhu:String;
- private var yuezhu:String;
- private var rizhu:String;
- private var jie:String;
- public function Taoshaw_data(yearOrTimevalue:Number, month:Number, date:Number, hour:Number, minute:Number, second:Number, millisecond:Number) {
- super(yearOrTimevalue, month, date, hour, minute, second, millisecond);
- var leap:Number = 0;
- var temp:Number = 0;
- var y:Number, m:Number, d;
- Number;
- y = getFullYear();
- m = getMonth();
- d = getDate();
- var offset = (Date.UTC(y, m, d)-Date.UTC(1900, 0, 31))/86400000;
- for (var i = 1900; i<2100 && offset>0; i++) {
- temp = lYearDays(i);
- offset -= temp;
- }
- if (offset<0) {
- offset += temp;
- i--;
- }
- cyear = i;
- leap = leapMonth(i);
- isLeap = false;
- for (var i = 1; i<13 && offset>0; i++) {
- if (leap>0 && i == (leap+1) && isLeap == false) {
- --i;
- isLeap = true;
- temp = leapDays(cyear);
- } else {
- temp = monthDays(cyear, i);
- }
- if (isLeap == true && i == (leap+1)) {
- isLeap = false;
- }
- offset -= temp;
- }
- if (offset == 0 && leap>0 && i == leap+1) {
- if (isLeap) {
- isLeap = false;
- } else {
- isLeap = true;
- --i;
- }
- }
- if (offset<0) {
- offset += temp;
- --i;
- }
- cmonth = i;
- cday = offset+1;
- var cY, cM, cD;
- if (m<2) {
- cY = cyclical(y-1900+36-1);
- } else {
- cY = cyclical(y-1900+36);
- }
- cM = cyclical((y-1900)*12+m+12);
- var tmp1 = sTerm(y, m*2);
- var tmp2 = sTerm(y, m*2+1);
- if (d == tmp1) {
- jie = tao_txtsolarTerm[m*2];
- } else {
- if (d == tmp2) {
- jie = tao_txtsolarTerm[m*2+1];
- } else {
- jie = "";
- }
- }
- this.jie = jie;
-
- var term2 = sTerm(y, 2);
- var firstNode = sTerm(y, m*2);
- if (m == 1 && d>=term2) {
- cY = cyclical(y-1900+36);
- trace("新年柱"+cY);
- }
- if ((d+1)>=firstNode) {
- cM = cyclical((y-1900)*12+m+13);
- }
- var dayCyclical = Date.UTC(y, m, 1, 0, 0, 0, 0)/86400000+25567+10;
- cD = cyclical(dayCyclical+d-1);
- nianzhu = cY;
- yuezhu = cM;
- rizhu = cD;
- }
- public function getTaosJYear():Number {
- return cyear;
- }
- public function getTaoJMonth():Number {
- return cmonth;
- }
- public function getTaoJDay():Number {
- return cday;
- }
-
- public function getnewMonth():Number {
- return getMonth()+1;
- }
- public function getTaoJNianZhu():String {
- return nianzhu;
- }
- public function getYueZhu():String {
- return yuezhu;
- }
- public function getRiZhu():String {
- return rizhu;
- }
- public function getJieQi():String {
- return jie;
- }
- public function getShiceng():String {
- return Zhi[Math.round((getHours()%23)/2)]+"时";
- }
- private function lYearDays(y) {
- var sum:Number = 348;
- for (var i = 0x8000; i>0x8; i >>= 1) {
- sum += (tao_txtnum_info[y-1900] & i) ? 1 : 0;
- }
- return (sum+leapDays(y));
- }
- private function leapDays(y) {
- if (leapMonth(y)) {
- return ((tao_txtnum_info[y-1899] & 0xf) == 0xf ? 30 : 29);
- } else {
- return (0);
- }
- }
- private function leapMonth(y) {
- var lm = tao_txtnum_info[y-1900] & 0xf;
- return (lm == 0xf ? 0 : lm);
- }
- private function monthDays(y, m) {
- return ((tao_txtnum_info[y-1900] & (0x10000 >> m)) ? 30 : 29);
- }
- private function sTerm(y, n) {
- var offDate = new Date((31556925974.7*(y-1900)+tao_txtsTermInfo[n]*60000)+Date.UTC(1900, 0, 6, 2, 5));
- return (offDate.getUTCDate());
- }
- private function solarDays(y, m) {
- if (m == 1) {
- return (((y%4 == 0) && (y%100 != 0) || (y%400 == 0)) ? 29 : 28);
- } else {
- return (tao_txtsolarMonth[m]);
- }
- }
- private function cyclical(num) {
- return (Gan[num%10]+Zhi[num%12]);
- }
- }
- 保存。
- 2、用法上面也写得有。在FLASH中调用的时候。请参考如下代码:
- onEnterFrame = function () {
- var my_data:Taoshaw_data = new Taoshaw_data();
-
- var my_xingqi:Array = new Array();
- my_xingqi = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
- var my_yuefen:Array = new Array();
- my_yuefen = ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"];
-
- var myhaoshu = my_data.getDate();
-
- var miao = my_data.getSeconds();
- var fen = my_data.getMinutes();
- if (fen<10) {
- fen = "0"+fen;
- } else {
- }
- if (miao<10) {
- miao = "0"+miao;
- } else {
- }
- if (myhaoshu<10) {
- myhaoshu = "0"+myhaoshu;
- } else {
- }
- show_txt.text = "现在是"+my_data.getFullYear()+"年"+my_yuefen[my_data.getMonth()]+myhaoshu+"号"+my_xingqi[my_data.getDay()]+my_data.getHours()+"时"+fen+"分"+miao+"秒。"+"旧历"+my_data.getTaosJYear()+"."+my_data.getTaoJMonth()+"."+my_data.getTaoJDay()+"农历"+my_data.getTaoJNianZhu()+"年"+my_data.getYueZhu()+"月"+my_data.getRiZhu()+"日"+my_data.getShiceng()+my_data.getJieQi();
- };
源码下载:http://download.csdn.net/source/830951
六、C++代码:
1、头文件
-
- #ifndef XDATE_H
- #define XDATE_H
- #include
- extern const WORD START_YEAR;
- extern const WORD END_YEAR ;
- class xDate
- {
- private:
- WORD m_iYear, m_iMonth, m_iDay;
- void l_InitData();
-
- static void l_CalcLunarDate(WORD &iYear, WORD &iMonth ,WORD &iDay,LONG iSpanDays);
-
- static WORD l_GetLunarHolDay(WORD iYear, WORD iMonth, WORD iDay);
- public:
-
- xDate(WORD iYear, WORD iMonth, WORD iDay);
- xDate();
-
- WORD GetYear(){return m_iYear;}
- WORD GetMonth(){return m_iMonth;}
- WORD GetDay(){return m_iDay;}
-
-
- void GetDate(WORD &iYear, WORD &iMonth, WORD &iDay);
- BOOL SetDate(WORD iYear , WORD iMonth , WORD iDay);
-
-
- static BOOL IsLeapYear(WORD iYear) {return !(iYear%4)&&(iYear%100) || !(iYear%400);}
-
-
- static WORD WeekDay(WORD iYear, WORD iMonth, WORD iDay);
-
-
- static WORD MonthDays(WORD iYear, WORD iMonth);
-
-
-
-
- static LONG LunarMonthDays(WORD iLunarYear, WORD iLunarMonth);
-
-
-
- static WORD LunarYearDays(WORD iLunarYear);
-
-
-
- static WORD GetLeapMonth(WORD iLunarYear);
-
-
- static void FormatLunarYear(WORD iYear, char *pBuffer);
-
- static void FormatMonth(WORD iMonth, char *pBuffer, BOOL bLunar = TRUE);
-
-
- static void FormatLunarDay(WORD iDay, char *pBuffer);
-
-
- static LONG CalcDateDiff(WORD iEndYear, WORD iEndMonth, WORD iEndDay,WORD iStartYear = START_YEAR,WORD iStartMonth =1, WORD iStartDay =1);
-
-
-
- static WORD GetLunarDate(WORD iYear, WORD iMonth, WORD iDay,WORD &iLunarYear, WORD &iLunarMonth, WORD &iLunarDay);
- };
- #endif //XDATE_H
2、实现文件
- #include "xDate.h"
- extern WORD gLunarMonthDay[];
- extern BYTE gLunarMonth[];
- extern BYTE gLunarHolDay[];
- const WORD START_YEAR =1901;
- const WORD END_YEAR =2050;
- void xDate::l_InitData()
- {
- SYSTEMTIME systime;
- ::GetSystemTime(&systime);
-
- m_iYear = systime.wYear;
- m_iMonth = systime.wMonth;
- m_iDay = systime.wDay;
- }
- xDate::xDate(WORD iYear, WORD iMonth, WORD iDay)
- {
- if(!SetDate(iYear, iMonth, iDay))
- l_InitData();
- }
- xDate::xDate()
- {
- l_InitData();
- }
- LONG xDate::CalcDateDiff(WORD iEndYear, WORD iEndMonth, WORD iEndDay,WORD iStartYear, WORD iStartMonth, WORD iStartDay)
- {
- WORD monthday[]={0, 31, 59 ,90, 120, 151, 181, 212, 243, 273, 304, 334};
-
- LONG iDiffDays =(iEndYear - iStartYear)*365;
- iDiffDays += (iEndYear-1)/4 - (iStartYear-1)/4;
- iDiffDays -= ((iEndYear-1)/100 - (iStartYear-1)/100);
- iDiffDays += (iEndYear-1)/400 - (iStartYear-1)/400;
-
- iDiffDays += monthday[iEndMonth-1] +
- (IsLeapYear(iEndYear)&&iEndMonth>2? 1: 0);
- iDiffDays += iEndDay;
-
- iDiffDays -= (monthday[iStartMonth-1] +(IsLeapYear(iStartYear)&&iStartMonth>2 ? 1: 0));
- iDiffDays -= iStartDay;
- return iDiffDays;
- }
- void xDate::l_CalcLunarDate(WORD &iYear, WORD &iMonth ,WORD &iDay, LONG iSpanDays)
- {
-
-
- if(iSpanDays <49)
- {
- iYear = START_YEAR-1;
- if(iSpanDays <19)
- {
- iMonth = 11;
- iDay = 11+WORD(iSpanDays);
- }
- else
- {
- iMonth = 12;
- iDay = WORD(iSpanDays) -18;
- }
- return ;
- }
-
- iSpanDays -=49;
- iYear = START_YEAR;
- iMonth = 1;
- iDay = 1;
-
- LONG tmp = LunarYearDays(iYear);
- while(iSpanDays >= tmp)
- {
- iSpanDays -= tmp;
- tmp = LunarYearDays(++iYear);
- }
-
- tmp = LOWORD(LunarMonthDays(iYear, iMonth));
- while(iSpanDays >= tmp)
- {
- iSpanDays -= tmp;
- if(iMonth == GetLeapMonth(iYear))
- {
- tmp = HIWORD(LunarMonthDays(iYear, iMonth));
- if(iSpanDays < tmp)
- break;
- iSpanDays -= tmp;
- }
- tmp = LOWORD(LunarMonthDays(iYear, ++iMonth));
- }
-
- iDay += WORD(iSpanDays);
- }
- WORD xDate::GetLunarDate(WORD iYear, WORD iMonth, WORD iDay,WORD &iLunarYear, WORD &iLunarMonth, WORD &iLunarDay)
- {
- l_CalcLunarDate(iLunarYear, iLunarMonth, iLunarDay,CalcDateDiff(iYear, iMonth, iDay));
- return l_GetLunarHolDay(iYear, iMonth, iDay);
- }
- WORD xDate::l_GetLunarHolDay(WORD iYear, WORD iMonth, WORD iDay)
- {
- BYTE &flag = gLunarHolDay[(iYear - START_YEAR)*12+iMonth -1];
- WORD day;
- if(iDay <15)
- day= 15 - ((flag>>4)&0x0f);
- else
- day = ((flag)&0x0f)+15;
- if(iDay == day)
- return (iMonth-1) *2 + (iDay>15? 1: 0) +1;
- else
- return 0;
- }
- void xDate::GetDate(WORD &iYear, WORD &iMonth, WORD &iDay)
- {
- iYear = m_iYear;
- iMonth = m_iMonth;
- iDay = m_iDay;
- }
- BOOL xDate::SetDate(WORD iYear, WORD iMonth, WORD iDay)
- {
- if(iYear < START_YEAR || iYear > END_YEAR || iMonth <1 || iMonth >12)
- return FALSE;
-
- if(iDay <1 || iDay > MonthDays(iYear, iMonth))
- return FALSE;
-
- m_iYear = iYear;
- m_iMonth = iMonth;
- m_iDay = iDay;
-
- return TRUE;
- }
- WORD xDate::WeekDay(WORD iYear, WORD iMonth, WORD iDay)
- {
-
- WORD monthday[]={0,3,3,6,1,4,6,2,5,0,3,5};
- WORD iDays = (iYear-1)%7 + (iYear-1)/4 - (iYear-1)/100 +(iYear-1)/400;
- iDays += (monthday[iMonth-1] +iDay) ;
-
- if(IsLeapYear(iYear) && iMonth>2)
- iDays++;
-
- return iDays%7;
- }
- WORD xDate::MonthDays(WORD iYear, WORD iMonth)
- {
- switch(iMonth)
- {
- case 1:
- case 3:
- case 5:
- case 7:
- case 8:
- case 10:
- case 12:
- return 31;
- case 4:
- case 6:
- case 9:
- case 11:
- return 30;
- case 2:
-
- if(IsLeapYear(iYear))
- return 29;
- else
- return 28;
-
- }
- return 0;
- }
- WORD xDate::GetLeapMonth(WORD iLunarYear)
- {
- BYTE &flag = gLunarMonth[(iLunarYear - START_YEAR)/2];
- return (iLunarYear - START_YEAR)%2 ? flag&0x0f : flag>>4;
- }
- LONG xDate::LunarMonthDays(WORD iLunarYear, WORD iLunarMonth)
- {
- if(iLunarYear < START_YEAR)
- return 30L;
-
- WORD height =0 ,low =29;
- int iBit = 16 - iLunarMonth;
-
- if(iLunarMonth > GetLeapMonth(iLunarYear) && GetLeapMonth(iLunarYear))
- iBit --;
-
- if(gLunarMonthDay[iLunarYear - START_YEAR] & (1<
- low ++;
-
- if(iLunarMonth == GetLeapMonth(iLunarYear))
- if(gLunarMonthDay[iLunarYear - START_YEAR] & (1<< (iBit -1)))
- height =30;
- else
- height =29;
-
- return MAKELONG(low, height);
- }
- WORD xDate::LunarYearDays(WORD iLunarYear)
- {
-
- WORD days =0;
- for(WORD i=1; i<=12; i++)
- {
- LONG tmp = LunarMonthDays(iLunarYear ,i);
- days += HIWORD(tmp);
- days += LOWORD(tmp);
- }
- return days;
- }
- void xDate::FormatLunarYear(WORD iYear, char *pBuffer)
- {
- char szText1[]="甲乙丙丁戊己庚辛壬癸";
- char szText2[]="子丑寅卯辰巳午未申酉戌亥";
- char szText3[]="鼠牛虎免龙蛇马羊猴鸡狗猪";
-
- memcpy(pBuffer ,szText1+((iYear-4)%10)*2,2);
- memcpy(pBuffer+2,szText2+((iYear-4)%12)*2,2);
- pBuffer[4]=' ';
- memcpy(pBuffer+5,szText3+((iYear-4)%12)*2,2);
- strcpy(pBuffer+7,"年");
- }
- void xDate::FormatMonth(WORD iMonth, char *pBuffer, BOOL bLunar)
- {
- if(!bLunar && iMonth==1)
- {
- strcpy(pBuffer, " 一月");
- return;
- }
- char szText[]="正二三四五六七八九十";
- if(iMonth<=10)
- {
- memcpy(pBuffer ," ", 2);
- memcpy(pBuffer+2, szText + (iMonth -1)*2, 2);
- strcpy(pBuffer+4, "月");
- return;
- }
- if (iMonth == 11)
- strcpy(pBuffer, "十一");
- else
- strcpy(pBuffer, "十二");
- strcpy(pBuffer+4 , "月");
-
-
- }
- void xDate::FormatLunarDay(WORD iDay, char *pBuffer)
- {
- char szText1[]="初十廿三";
- char szText2[]="一二三四五六七八九十";
- if(iDay != 20 && iDay !=30)
- {
- memcpy(pBuffer , szText1 + (iDay-1)/10*2 ,2);
- memcpy(pBuffer+2, szText2 + ((iDay-1)%10)*2 ,2);
- pBuffer[4]='/0';
- }
- else
- {
- memcpy(pBuffer , szText1 + iDay/10*2, 2);
- strcpy(pBuffer+2, szText2 +18);
- }
- }
-
-
- WORD gLunarMonthDay[]=
- {
-
- 0X4ae0, 0Xa570, 0X5268, 0Xd260, 0Xd950, 0X6aa8, 0X56a0, 0X9ad0, 0X4ae8, 0X4ae0,
- 0Xa4d8, 0Xa4d0, 0Xd250, 0Xd548, 0Xb550, 0X56a0, 0X96d0, 0X95b0, 0X49b8, 0X49b0,
- 0Xa4b0, 0Xb258, 0X6a50, 0X6d40, 0Xada8, 0X2b60, 0X9570, 0X4978, 0X4970, 0X64b0,
- 0Xd4a0, 0Xea50, 0X6d48, 0X5ad0, 0X2b60, 0X9370, 0X92e0, 0Xc968, 0Xc950, 0Xd4a0,
- 0Xda50, 0Xb550, 0X56a0, 0Xaad8, 0X25d0, 0X92d0, 0Xc958, 0Xa950, 0Xb4a8, 0X6ca0,
- 0Xb550, 0X55a8, 0X4da0, 0Xa5b0, 0X52b8, 0X52b0, 0Xa950, 0Xe950, 0X6aa0, 0Xad50,
- 0Xab50, 0X4b60, 0Xa570, 0Xa570, 0X5260, 0Xe930, 0Xd950, 0X5aa8, 0X56a0, 0X96d0,
- 0X4ae8, 0X4ad0, 0Xa4d0, 0Xd268, 0Xd250, 0Xd528, 0Xb540, 0Xb6a0, 0X96d0, 0X95b0,
- 0X49b0, 0Xa4b8, 0Xa4b0, 0Xb258, 0X6a50, 0X6d40, 0Xada0, 0Xab60, 0X9370, 0X4978,
- 0X4970, 0X64b0, 0X6a50, 0Xea50, 0X6b28, 0X5ac0, 0Xab60, 0X9368, 0X92e0, 0Xc960,
- 0Xd4a8, 0Xd4a0, 0Xda50, 0X5aa8, 0X56a0, 0Xaad8, 0X25d0, 0X92d0, 0Xc958, 0Xa950,
- 0Xb4a0, 0Xb550, 0Xb550, 0X55a8, 0X4ba0, 0Xa5b0, 0X52b8, 0X52b0, 0Xa930, 0X74a8,
- 0X6aa0, 0Xad50, 0X4da8, 0X4b60, 0X9570, 0Xa4e0, 0Xd260, 0Xe930, 0Xd530, 0X5aa0,
- 0X6b50, 0X96d0, 0X4ae8, 0X4ad0, 0Xa4d0, 0Xd258, 0Xd250, 0Xd520, 0Xdaa0, 0Xb5a0,
- 0X56d0, 0X4ad8, 0X49b0, 0Xa4b8, 0Xa4b0, 0Xaa50, 0Xb528, 0X6d20, 0Xada0, 0X55b0,
-
- };
- BYTE gLunarMonth[]=
- {
- 0X00, 0X50, 0X04, 0X00, 0X20,
- 0X60, 0X05, 0X00, 0X20, 0X70,
- 0X05, 0X00, 0X40, 0X02, 0X06,
- 0X00, 0X50, 0X03, 0X07, 0X00,
- 0X60, 0X04, 0X00, 0X20, 0X70,
- 0X05, 0X00, 0X30, 0X80, 0X06,
- 0X00, 0X40, 0X03, 0X07, 0X00,
- 0X50, 0X04, 0X08, 0X00, 0X60,
- 0X04, 0X0a, 0X00, 0X60, 0X05,
- 0X00, 0X30, 0X80, 0X05, 0X00,
- 0X40, 0X02, 0X07, 0X00, 0X50,
- 0X04, 0X09, 0X00, 0X60, 0X04,
- 0X00, 0X20, 0X60, 0X05, 0X00,
- 0X30, 0Xb0, 0X06, 0X00, 0X50,
- 0X02, 0X07, 0X00, 0X50, 0X03
- };
-
- BYTE gLunarHolDay[]=
- {
- 0X96, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X78, 0X79, 0X79, 0X69, 0X78, 0X77,
- 0X96, 0XA4, 0X96, 0X96, 0X97, 0X87, 0X79, 0X79, 0X79, 0X69, 0X78, 0X78,
- 0X96, 0XA5, 0X87, 0X96, 0X87, 0X87, 0X79, 0X69, 0X69, 0X69, 0X78, 0X78,
- 0X86, 0XA5, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X79, 0X78, 0X87,
- 0X96, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X78, 0X79, 0X79, 0X69, 0X78, 0X77,
- 0X96, 0XA4, 0X96, 0X96, 0X97, 0X97, 0X79, 0X79, 0X79, 0X69, 0X78, 0X78,
- 0X96, 0XA5, 0X87, 0X96, 0X87, 0X87, 0X79, 0X69, 0X69, 0X69, 0X78, 0X78,
- 0X86, 0XA5, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X69, 0X78, 0X87,
- 0X96, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X78, 0X79, 0X79, 0X69, 0X78, 0X77,
- 0X96, 0XA4, 0X96, 0X96, 0X97, 0X97, 0X79, 0X79, 0X79, 0X69, 0X78, 0X78,
- 0X96, 0XA5, 0X87, 0X96, 0X87, 0X87, 0X79, 0X69, 0X69, 0X69, 0X78, 0X78,
- 0X86, 0XA5, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X69, 0X78, 0X87,
- 0X95, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X78, 0X79, 0X79, 0X69, 0X78, 0X77,
- 0X96, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X79, 0X79, 0X79, 0X69, 0X78, 0X78,
- 0X96, 0XA5, 0X97, 0X96, 0X97, 0X87, 0X79, 0X79, 0X69, 0X69, 0X78, 0X78,
- 0X96, 0XA5, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X79, 0X77, 0X87,
- 0X95, 0XB4, 0X96, 0XA6, 0X96, 0X97, 0X78, 0X79, 0X78, 0X69, 0X78, 0X87,
- 0X96, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X79, 0X79, 0X79, 0X69, 0X78, 0X77,
- 0X96, 0XA5, 0X97, 0X96, 0X97, 0X87, 0X79, 0X79, 0X69, 0X69, 0X78, 0X78,
- 0X96, 0XA5, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X79, 0X77, 0X87,
- 0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X78, 0X79, 0X78, 0X69, 0X78, 0X87,
- 0X96, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X79, 0X79, 0X79, 0X69, 0X78, 0X77,
- 0X96, 0XA4, 0X96, 0X96, 0X97, 0X87, 0X79, 0X79, 0X69, 0X69, 0X78, 0X78,
- 0X96, 0XA5, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X79, 0X77, 0X87,
- 0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X78, 0X79, 0X78, 0X69, 0X78, 0X87,
- 0X96, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X78, 0X79, 0X79, 0X69, 0X78, 0X77,
- 0X96, 0XA4, 0X96, 0X96, 0X97, 0X87, 0X79, 0X79, 0X79, 0X69, 0X78, 0X78,
- 0X96, 0XA5, 0X96, 0XA5, 0X96, 0X96, 0X88, 0X78, 0X78, 0X78, 0X87, 0X87,
- 0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X79, 0X77, 0X87,
- 0X96, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X78, 0X79, 0X79, 0X69, 0X78, 0X77,
- 0X96, 0XA4, 0X96, 0X96, 0X97, 0X87, 0X79, 0X79, 0X79, 0X69, 0X78, 0X78,
- 0X96, 0XA5, 0X96, 0XA5, 0X96, 0X96, 0X88, 0X78, 0X78, 0X78, 0X87, 0X87,
- 0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X69, 0X78, 0X87,
- 0X96, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X78, 0X79, 0X79, 0X69, 0X78, 0X77,
- 0X96, 0XA4, 0X96, 0X96, 0X97, 0X97, 0X79, 0X79, 0X79, 0X69, 0X78, 0X78,
- 0X96, 0XA5, 0X96, 0XA5, 0X96, 0X96, 0X88, 0X78, 0X78, 0X78, 0X87, 0X87,
- 0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X69, 0X78, 0X87,
- 0X96, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X78, 0X79, 0X79, 0X69, 0X78, 0X77,
- 0X96, 0XA4, 0X96, 0X96, 0X97, 0X97, 0X79, 0X79, 0X79, 0X69, 0X78, 0X78,
- 0X96, 0XA5, 0X96, 0XA5, 0X96, 0X96, 0X88, 0X78, 0X78, 0X78, 0X87, 0X87,
- 0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X69, 0X78, 0X87,
- 0X96, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X78, 0X79, 0X79, 0X69, 0X78, 0X77,
- 0X96, 0XA4, 0X96, 0X96, 0X97, 0X97, 0X79, 0X79, 0X79, 0X69, 0X78, 0X78,
- 0X96, 0XA5, 0X96, 0XA5, 0XA6, 0X96, 0X88, 0X78, 0X78, 0X78, 0X87, 0X87,
- 0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X79, 0X77, 0X87,
- 0X95, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X78, 0X79, 0X78, 0X69, 0X78, 0X77,
- 0X96, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X79, 0X79, 0X79, 0X69, 0X78, 0X78,
- 0X96, 0XA5, 0XA6, 0XA5, 0XA6, 0X96, 0X88, 0X88, 0X78, 0X78, 0X87, 0X87,
- 0XA5, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X79, 0X78, 0X79, 0X77, 0X87,
- 0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X78, 0X79, 0X78, 0X69, 0X78, 0X77,
- 0X96, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X79, 0X79, 0X79, 0X69, 0X78, 0X78,
- 0X96, 0XA5, 0XA6, 0XA5, 0XA6, 0X96, 0X88, 0X88, 0X78, 0X78, 0X87, 0X87,
- 0XA5, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X79, 0X77, 0X87,
- 0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X78, 0X79, 0X78, 0X68, 0X78, 0X87,
- 0X96, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X78, 0X79, 0X79, 0X69, 0X78, 0X77,
- 0X96, 0XA5, 0XA5, 0XA5, 0XA6, 0X96, 0X88, 0X88, 0X78, 0X78, 0X87, 0X87,
- 0XA5, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X79, 0X77, 0X87,
- 0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X69, 0X78, 0X87,
- 0X96, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X78, 0X79, 0X79, 0X69, 0X78, 0X77,
- 0X96, 0XA4, 0XA5, 0XA5, 0XA6, 0X96, 0X88, 0X88, 0X88, 0X78, 0X87, 0X87,
- 0XA5, 0XB4, 0X96, 0XA5, 0X96, 0X96, 0X88, 0X78, 0X78, 0X78, 0X87, 0X87,
- 0X96, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X69, 0X78, 0X87,
- 0X96, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X78, 0X79, 0X79, 0X69, 0X78, 0X77,
- 0X96, 0XA4, 0XA5, 0XA5, 0XA6, 0X96, 0X88, 0X88, 0X88, 0X78, 0X87, 0X87,
- 0XA5, 0XB4, 0X96, 0XA5, 0X96, 0X96, 0X88, 0X78, 0X78, 0X78, 0X87, 0X87,
- 0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X69, 0X78, 0X87,
- 0X96, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X78, 0X79, 0X79, 0X69, 0X78, 0X77,
- 0X96, 0XA4, 0XA5, 0XA5, 0XA6, 0XA6, 0X88, 0X88, 0X88, 0X78, 0X87, 0X87,
- 0XA5, 0XB4, 0X96, 0XA5, 0X96, 0X96, 0X88, 0X78, 0X78, 0X78, 0X87, 0X87,
- 0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X69, 0X78, 0X87,
- 0X96, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X78, 0X79, 0X79, 0X69, 0X78, 0X77,
- 0X96, 0XA4, 0XA5, 0XA5, 0XA6, 0XA6, 0X88, 0X88, 0X88, 0X78, 0X87, 0X87,
- 0XA5, 0XB5, 0X96, 0XA5, 0XA6, 0X96, 0X88, 0X78, 0X78, 0X78, 0X87, 0X87,
- 0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X69, 0X78, 0X87,
- 0X96, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X78, 0X79, 0X78, 0X69, 0X78, 0X77,
- 0X96, 0XA4, 0XA5, 0XB5, 0XA6, 0XA6, 0X88, 0X89, 0X88, 0X78, 0X87, 0X87,
- 0XA5, 0XB4, 0X96, 0XA5, 0X96, 0X96, 0X88, 0X88, 0X78, 0X78, 0X87, 0X87,
- 0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X79, 0X78, 0X87,
- 0X96, 0XB4, 0X96, 0XA6, 0X96, 0X97, 0X78, 0X79, 0X78, 0X69, 0X78, 0X77,
- 0X96, 0XA4, 0XA5, 0XB5, 0XA6, 0XA6, 0X88, 0X88, 0X88, 0X78, 0X87, 0X87,
- 0XA5, 0XB4, 0X96, 0XA5, 0XA6, 0X96, 0X88, 0X88, 0X78, 0X78, 0X77, 0X87,
- 0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X79, 0X77, 0X87,
- 0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X78, 0X79, 0X78, 0X69, 0X78, 0X77,
- 0X96, 0XB4, 0XA5, 0XB5, 0XA6, 0XA6, 0X87, 0X88, 0X88, 0X78, 0X87, 0X87,
- 0XA5, 0XB4, 0XA6, 0XA5, 0XA6, 0X96, 0X88, 0X88, 0X78, 0X78, 0X87, 0X87,
- 0XA5, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X79, 0X77, 0X87,
- 0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X79, 0X78, 0X69, 0X78, 0X87,
- 0X96, 0XB4, 0XA5, 0XB5, 0XA6, 0XA6, 0X87, 0X88, 0X88, 0X78, 0X87, 0X86,
- 0XA5, 0XB4, 0XA5, 0XA5, 0XA6, 0X96, 0X88, 0X88, 0X88, 0X78, 0X87, 0X87,
- 0XA5, 0XB4, 0X96, 0XA5, 0X96, 0X96, 0X88, 0X78, 0X78, 0X79, 0X77, 0X87,
- 0X95, 0XB4, 0X96, 0XA5, 0X86, 0X97, 0X88, 0X78, 0X78, 0X69, 0X78, 0X87,
- 0X96, 0XB4, 0XA5, 0XB5, 0XA6, 0XA6, 0X87, 0X88, 0X88, 0X78, 0X87, 0X86,
- 0XA5, 0XB3, 0XA5, 0XA5, 0XA6, 0X96, 0X88, 0X88, 0X88, 0X78, 0X87, 0X87,
- 0XA5, 0XB4, 0X96, 0XA5, 0X96, 0X96, 0X88, 0X78, 0X78, 0X78, 0X87, 0X87,
- 0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X76, 0X78, 0X69, 0X78, 0X87,
- 0X96, 0XB4, 0XA5, 0XB5, 0XA6, 0XA6, 0X87, 0X88, 0X88, 0X78, 0X87, 0X86,
- 0XA5, 0XB3, 0XA5, 0XA5, 0XA6, 0XA6, 0X88, 0X88, 0X88, 0X78, 0X87, 0X87,
- 0XA5, 0XB4, 0X96, 0XA5, 0X96, 0X96, 0X88, 0X78, 0X78, 0X78, 0X87, 0X87,
- 0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X69, 0X78, 0X87,
- 0X96, 0XB4, 0XA5, 0XB5, 0XA6, 0XA6, 0X87, 0X88, 0X88, 0X78, 0X87, 0X86,
- 0XA5, 0XB3, 0XA5, 0XA5, 0XA6, 0XA6, 0X88, 0X88, 0X88, 0X78, 0X87, 0X87,
- 0XA5, 0XB4, 0X96, 0XA5, 0X96, 0X96, 0X88, 0X78, 0X78, 0X78, 0X87, 0X87,
- 0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X69, 0X78, 0X87,
- 0X96, 0XB4, 0XA5, 0XB5, 0XA6, 0XA6, 0X87, 0X88, 0X88, 0X78, 0X87, 0X86,
- 0XA5, 0XB3, 0XA5, 0XA5, 0XA6, 0XA6, 0X88, 0X88, 0X88, 0X78, 0X87, 0X87,
- 0XA5, 0XB4, 0X96, 0XA5, 0XA6, 0X96, 0X88, 0X88, 0X78, 0X78, 0X87, 0X87,
- 0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X69, 0X78, 0X87,
- 0X96, 0XB4, 0XA5, 0XB5, 0XA6, 0XA6, 0X87, 0X88, 0X87, 0X78, 0X87, 0X86,
- 0XA5, 0XB3, 0XA5, 0XB5, 0XA6, 0XA6, 0X88, 0X88, 0X88, 0X78, 0X87, 0X87,
- 0XA5, 0XB4, 0X96, 0XA5, 0XA6, 0X96, 0X88, 0X88, 0X78, 0X78, 0X87, 0X87,
- 0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X79, 0X78, 0X87,
- 0X96, 0XB4, 0XA5, 0XB5, 0XA5, 0XA6, 0X87, 0X88, 0X87, 0X78, 0X87, 0X86,
- 0XA5, 0XB3, 0XA5, 0XB5, 0XA6, 0XA6, 0X87, 0X88, 0X88, 0X78, 0X87, 0X87,
- 0XA5, 0XB4, 0X96, 0XA5, 0XA6, 0X96, 0X88, 0X88, 0X78, 0X78, 0X87, 0X87,
- 0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X79, 0X77, 0X87,
- 0X95, 0XB4, 0XA5, 0XB4, 0XA5, 0XA6, 0X87, 0X88, 0X87, 0X78, 0X87, 0X86,
- 0XA5, 0XC3, 0XA5, 0XB5, 0XA6, 0XA6, 0X87, 0X88, 0X88, 0X78, 0X87, 0X87,
- 0XA5, 0XB4, 0XA6, 0XA5, 0XA6, 0X96, 0X88, 0X88, 0X78, 0X78, 0X87, 0X87,
- 0XA5, 0XB4, 0X96, 0XA5, 0X96, 0X96, 0X88, 0X78, 0X78, 0X79, 0X77, 0X87,
- 0X95, 0XB4, 0XA5, 0XB4, 0XA5, 0XA6, 0X97, 0X87, 0X87, 0X78, 0X87, 0X86,
- 0XA5, 0XC3, 0XA5, 0XB5, 0XA6, 0XA6, 0X87, 0X88, 0X88, 0X78, 0X87, 0X86,
- 0XA5, 0XB4, 0XA5, 0XA5, 0XA6, 0X96, 0X88, 0X88, 0X88, 0X78, 0X87, 0X87,
- 0XA5, 0XB4, 0X96, 0XA5, 0X96, 0X96, 0X88, 0X78, 0X78, 0X79, 0X77, 0X87,
- 0X95, 0XB4, 0XA5, 0XB4, 0XA5, 0XA6, 0X97, 0X87, 0X87, 0X78, 0X87, 0X96,
- 0XA5, 0XC3, 0XA5, 0XB5, 0XA6, 0XA6, 0X87, 0X88, 0X88, 0X78, 0X87, 0X86,
- 0XA5, 0XB3, 0XA5, 0XA5, 0XA6, 0XA6, 0X88, 0X88, 0X88, 0X78, 0X87, 0X87,
- 0XA5, 0XB4, 0X96, 0XA5, 0X96, 0X96, 0X88, 0X78, 0X78, 0X78, 0X87, 0X87,
- 0X95, 0XB4, 0XA5, 0XB4, 0XA5, 0XA6, 0X97, 0X87, 0X87, 0X78, 0X87, 0X96,
- 0XA5, 0XC3, 0XA5, 0XB5, 0XA6, 0XA6, 0X87, 0X88, 0X88, 0X78, 0X87, 0X86,
- 0XA5, 0XB3, 0XA5, 0XA5, 0XA6, 0XA6, 0X88, 0X88, 0X88, 0X78, 0X87, 0X87,
- 0XA5, 0XB4, 0X96, 0XA5, 0X96, 0X96, 0X88, 0X78, 0X78, 0X78, 0X87, 0X87,
- 0X95, 0XB4, 0XA5, 0XB4, 0XA5, 0XA6, 0X97, 0X87, 0X87, 0X78, 0X87, 0X96,
- 0XA5, 0XC3, 0XA5, 0XB5, 0XA6, 0XA6, 0X88, 0X88, 0X88, 0X78, 0X87, 0X86,
- 0XA5, 0XB3, 0XA5, 0XA5, 0XA6, 0XA6, 0X88, 0X78, 0X88, 0X78, 0X87, 0X87,
- 0XA5, 0XB4, 0X96, 0XA5, 0XA6, 0X96, 0X88, 0X88, 0X78, 0X78, 0X87, 0X87,
- 0X95, 0XB4, 0XA5, 0XB4, 0XA5, 0XA6, 0X97, 0X87, 0X87, 0X78, 0X87, 0X96,
- 0XA5, 0XC3, 0XA5, 0XB5, 0XA6, 0XA6, 0X87, 0X88, 0X88, 0X78, 0X87, 0X86,
- 0XA5, 0XB3, 0XA5, 0XA5, 0XA6, 0XA6, 0X88, 0X88, 0X88, 0X78, 0X87, 0X87,
- 0XA5, 0XB4, 0X96, 0XA5, 0XA6, 0X96, 0X88, 0X88, 0X78, 0X78, 0X87, 0X87,
- 0X95, 0XB4, 0XA5, 0XB4, 0XA5, 0XA6, 0X97, 0X87, 0X87, 0X78, 0X87, 0X96,
- 0XA5, 0XC3, 0XA5, 0XB5, 0XA5, 0XA6, 0X87, 0X88, 0X87, 0X78, 0X87, 0X86,
- 0XA5, 0XB3, 0XA5, 0XB5, 0XA6, 0XA6, 0X88, 0X88, 0X88, 0X78, 0X87, 0X87,
- 0XA5, 0XB4, 0X96, 0XA5, 0XA6, 0X96, 0X88, 0X88, 0X78, 0X78, 0X87, 0X87,
- 0X95, 0XB4, 0XA5, 0XB4, 0XA5, 0XA6, 0X97, 0X87, 0X87, 0X88, 0X87, 0X96,
- 0XA5, 0XC3, 0XA5, 0XB4, 0XA5, 0XA6, 0X87, 0X88, 0X87, 0X78, 0X87, 0X86,
- 0XA5, 0XB3, 0XA5, 0XB5, 0XA6, 0XA6, 0X87, 0X88, 0X88, 0X78, 0X87, 0X87,
- 0XA5, 0XB4, 0X96, 0XA5, 0XA6, 0X96, 0X88, 0X88, 0X78, 0X78, 0X87, 0X87,
- 0X95, 0XB4, 0XA5, 0XB4, 0XA5, 0XA5, 0X97, 0X87, 0X87, 0X88, 0X86, 0X96,
- 0XA4, 0XC3, 0XA5, 0XA5, 0XA5, 0XA6, 0X97, 0X87, 0X87, 0X78, 0X87, 0X86,
- 0XA5, 0XC3, 0XA5, 0XB5, 0XA6, 0XA6, 0X87, 0X88, 0X78, 0X78, 0X87, 0X87
-
- };
(感谢baickl)
七、C语言(1):
前段时间做软件写了个公历转农历的函数,目前公开给大家参考,有兴趣的朋友可以在此基础上进一步完善其功能。
-
- char *GetDayOf(PSYSTEMTIME pSt)
- {
-
- const char *cTianGan[] = {"甲","乙","丙","丁","戊","己","庚","辛","壬","癸"};
-
- const char *cDiZhi[] = {"子","丑","寅","卯","辰","巳","午",
- "未","申","酉","戌","亥"};
-
- const char *cShuXiang[] = {"鼠","牛","虎","兔","龙","蛇",
- "马","羊","猴","鸡","狗","猪"};
-
- const char *cDayName[] = {"*","初一","初二","初三","初四","初五",
- "初六","初七","初八","初九","初十",
- "十一","十二","十三","十四","十五",
- "十六","十七","十八","十九","二十",
- "廿一","廿二","廿三","廿四","廿五",
- "廿六","廿七","廿八","廿九","三十"};
-
- const char *cMonName[] = {"*","正","二","三","四","五","六",
- "七","八","九","十","十一","腊"};
-
- const int wMonthAdd[12] = {0,31,59,90,120,151,181,212,243,273,304,334};
-
- const int wNongliData[100] = {2635,333387,1701,1748,267701,694,2391,133423,1175,396438
- ,3402,3749,331177,1453,694,201326,2350,465197,3221,3402
- ,400202,2901,1386,267611,605,2349,137515,2709,464533,1738
- ,2901,330421,1242,2651,199255,1323,529706,3733,1706,398762
- ,2741,1206,267438,2647,1318,204070,3477,461653,1386,2413
- ,330077,1197,2637,268877,3365,531109,2900,2922,398042,2395
- ,1179,267415,2635,661067,1701,1748,398772,2742,2391,330031
- ,1175,1611,200010,3749,527717,1452,2742,332397,2350,3222
- ,268949,3402,3493,133973,1386,464219,605,2349,334123,2709
- ,2890,267946,2773,592565,1210,2651,395863,1323,2707,265877};
- static int wCurYear,wCurMonth,wCurDay;
- static int nTheDate,nIsEnd,m,k,n,i,nBit;
- TCHAR szNongli[30], szNongliDay[10],szShuXiang[10];
-
- wCurYear = pSt->wYear;
- wCurMonth = pSt->wMonth;
- wCurDay = pSt->wDay;
-
- nTheDate = (wCurYear - 1921) * 365 + (wCurYear - 1921) / 4 + wCurDay + wMonthAdd[wCurMonth - 1] - 38;
- if((!(wCurYear % 4)) && (wCurMonth > 2))
- nTheDate = nTheDate + 1;
-
- nIsEnd = 0;
- m = 0;
- while(nIsEnd != 1)
- {
- if(wNongliData[m] < 4095)
- k = 11;
- else
- k = 12;
- n = k;
- while(n>=0)
- {
-
- nBit = wNongliData[m];
- for(i=1;i
- nBit = nBit/2;
- nBit = nBit % 2;
- if (nTheDate <= (29 + nBit))
- {
- nIsEnd = 1;
- break;
- }
- nTheDate = nTheDate - 29 - nBit;
- n = n - 1;
- }
- if(nIsEnd)
- break;
- m = m + 1;
- }
- wCurYear = 1921 + m;
- wCurMonth = k - n + 1;
- wCurDay = nTheDate;
- if (k == 12)
- {
- if (wCurMonth == wNongliData[m] / 65536 + 1)
- wCurMonth = 1 - wCurMonth;
- else if (wCurMonth > wNongliData[m] / 65536 + 1)
- wCurMonth = wCurMonth - 1;
- }
-
- wsprintf(szShuXiang,"%s",cShuXiang[((wCurYear - 4) % 60) % 12]);
- wsprintf(szNongli,"%s(%s%s)年",szShuXiang,cTianGan[((wCurYear - 4) % 60) % 10],cDiZhi[((wCurYear - 4) % 60) % 12]);
-
- if (wCurMonth < 1)
- wsprintf(szNongliDay,"闰%s",cMonName[-1 * wCurMonth]);
- else
- strcpy(szNongliDay,cMonName[wCurMonth]);
- strcat(szNongliDay,"月");
- strcat(szNongliDay,cDayName[wCurDay]);
- return strcat(szNongli,szNongliDay);
- }
(感谢CSDN作者3661512)
八、C语言(2):
-
- #define firstyear 1936 /* the first year in lunarcal[] */
- struct convdate
- {
- int source;
- int solaryear;
- int solarmonth;
- int solardate;
- int lunaryear;
- int lunarmonth;
- int lunardate;
- int weekday;
- int kan;
- int chih;
- };
- struct taglunarcal
- {
- int basedays;
- int intercalation;
- int baseweekday;
- int basekanchih;
- int monthdays[13];
- };
- struct taglunarcal lunarcal[] = {
- { 23, 3, 2, 17, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0 },
- { 41, 0, 4, 23, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1 },
- { 30, 7, 5, 28, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1 },
- { 49, 0, 6, 33, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1 },
- { 38, 0, 0, 38, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 },
- { 26, 6, 2, 44, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0 },
- { 45, 0, 3, 49, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 },
- { 35, 0, 4, 54, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1 },
- { 24, 4, 5, 59, 1, 0, 1, 0,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 },
- { 35, 0, 1, 33, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0 },
- { 24, 4, 2, 38, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 },
- { 42, 0, 4, 44, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 },
- { 31, 0, 5, 49, 1, 0, 1, 0, 1, 1, 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 },
- { 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 },
- { 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 };
-
- 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 } };
-
- 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 )
- {
- 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
- {
- 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;
- }
(感谢各位作者)
文献:
1、http://www.25175.com/200609/25175/25175_html/2006-11/936.html
2、http://hi.baidu.com/wangleiit/blog/item/d2ef51088122bf910b7b827c.html
3、http://www.supesoft.com/ArticleDisp.asp?ID=4618
4、http://www.cnblogs.com/panjiwen/archive/2006/02/06/326159.html
5、http://www.taoshaw.com/taoshaw/article.asp?id=1494
6、http://www.pcjx.com/Dotnet/C/208963.html
7、http://study.feloo.com/gaokao_news.do?infoID=50354