C# 万年历 农历 节气 节日 星座 星宿 属相 生肖 闰年月 时辰等,代码如下:

  1. using System.Collections.Generic;
  2. using System.Text;
  3.  
  4. using System;
  5.  
  6. namespace yangliToyinli
  7. {
  8. #region ChineseCalendarException
  9. /// <summary>
  10. /// 中国日历异常处理
  11. /// </summary>
  12. public class ChineseCalendarException : System.Exception
  13. {
  14. public ChineseCalendarException(string msg)
  15. : base(msg)
  16. {
  17. }
  18. }
  19.  
  20. #endregion
  21.  
  22. /// <summary>
  23. /// 中国农历类 版本V1.0 支持 1900.1.31日起至 2049.12.31日止的数据
  24. /// </summary>
  25. /// <remarks>
  26. /// 本程序使用数据来源于网上的万年历查询,并综合了一些其它数据
  27. /// </remarks>
  28. public class ChineseCalendar
  29. {
  30. #region 内部结构
  31. private struct SolarHolidayStruct
  32. {
  33. public int Month;
  34. public int Day;
  35. public int Recess; //假期长度
  36. public string HolidayName;
  37. public SolarHolidayStruct(int month, int day, int recess, string name)
  38. {
  39. Month = month;
  40. Day = day;
  41. Recess = recess;
  42. HolidayName = name;
  43. }
  44. }
  45.  
  46. private struct LunarHolidayStruct
  47. {
  48. public int Month;
  49. public int Day;
  50. public int Recess;
  51. public string HolidayName;
  52.  
  53. public LunarHolidayStruct(int month, int day, int recess, string name)
  54. {
  55. Month = month;
  56. Day = day;
  57. Recess = recess;
  58. HolidayName = name;
  59. }
  60. }
  61.  
  62. private struct WeekHolidayStruct
  63. {
  64. public int Month;
  65. public int WeekAtMonth;
  66. public int WeekDay;
  67. public string HolidayName;
  68.  
  69. public WeekHolidayStruct(int month, int weekAtMonth, int weekDay, string name)
  70. {
  71. Month = month;
  72. WeekAtMonth = weekAtMonth;
  73. WeekDay = weekDay;
  74. HolidayName = name;
  75. }
  76. }
  77. #endregion
  78.  
  79. #region 内部变量
  80. private DateTime _date;
  81. private DateTime _datetime;
  82.  
  83. private int _cYear;
  84. private int _cMonth;
  85. private int _cDay;
  86. private bool _cIsLeapMonth; //当月是否闰月
  87. private bool _cIsLeapYear; //当年是否有闰月
  88. #endregion
  89.  
  90. #region 基础数据
  91. #region 基本常量
  92. private const int MinYear = ;
  93. private const int MaxYear = ;
  94. private static DateTime MinDay = new DateTime(, , );
  95. private static DateTime MaxDay = new DateTime(, , );
  96. private const int GanZhiStartYear = ; //干支计算起始年
  97. private static DateTime GanZhiStartDay = new DateTime(, , );//起始日
  98. private const string HZNum = "零一二三四五六七八九";
  99. private const int AnimalStartYear = ; //1900年为鼠年
  100. private static DateTime ChineseConstellationReferDay = new DateTime(, , );//28星宿参考值,本日为角
  101. #endregion
  102.  
  103. #region 阴历数据
  104. /// <summary>
  105. /// 来源于网上的农历数据
  106. /// </summary>
  107. /// <remarks>
  108. /// 数据结构如下,共使用17位数据
  109. /// 第17位:表示闰月天数,0表示29天 1表示30天
  110. /// 第16位-第5位(共12位)表示12个月,其中第16位表示第一月,如果该月为30天则为1,29天为0
  111. /// 第4位-第1位(共4位)表示闰月是哪个月,如果当年没有闰月,则置0
  112. ///</remarks>
  113. private static int[] LunarDateArray = new int[]{
  114. x04BD8,0x04AE0,0x0A570,0x054D5,0x0D260,0x0D950,0x16554,0x056A0,0x09AD0,0x055D2,
  115. x04AE0,0x0A5B6,0x0A4D0,0x0D250,0x1D255,0x0B540,0x0D6A0,0x0ADA2,0x095B0,0x14977,
  116. x04970,0x0A4B0,0x0B4B5,0x06A50,0x06D40,0x1AB54,0x02B60,0x09570,0x052F2,0x04970,
  117. x06566,0x0D4A0,0x0EA50,0x06E95,0x05AD0,0x02B60,0x186E3,0x092E0,0x1C8D7,0x0C950,
  118. x0D4A0,0x1D8A6,0x0B550,0x056A0,0x1A5B4,0x025D0,0x092D0,0x0D2B2,0x0A950,0x0B557,
  119. x06CA0,0x0B550,0x15355,0x04DA0,0x0A5B0,0x14573,0x052B0,0x0A9A8,0x0E950,0x06AA0,
  120. x0AEA6,0x0AB50,0x04B60,0x0AAE4,0x0A570,0x05260,0x0F263,0x0D950,0x05B57,0x056A0,
  121. x096D0,0x04DD5,0x04AD0,0x0A4D0,0x0D4D4,0x0D250,0x0D558,0x0B540,0x0B6A0,0x195A6,
  122. x095B0,0x049B0,0x0A974,0x0A4B0,0x0B27A,0x06A50,0x06D40,0x0AF46,0x0AB60,0x09570,
  123. x04AF5,0x04970,0x064B0,0x074A3,0x0EA50,0x06B58,0x055C0,0x0AB60,0x096D5,0x092E0,
  124. x0C960,0x0D954,0x0D4A0,0x0DA50,0x07552,0x056A0,0x0ABB7,0x025D0,0x092D0,0x0CAB5,
  125. x0A950,0x0B4A0,0x0BAA4,0x0AD50,0x055D9,0x04BA0,0x0A5B0,0x15176,0x052B0,0x0A930,
  126. x07954,0x06AA0,0x0AD50,0x05B52,0x04B60,0x0A6E6,0x0A4E0,0x0D260,0x0EA65,0x0D530,
  127. x05AA0,0x076A3,0x096D0,0x04BD7,0x04AD0,0x0A4D0,0x1D0B6,0x0D250,0x0D520,0x0DD45,
  128. x0B5A0,0x056D0,0x055B2,0x049B0,0x0A577,0x0A4B0,0x0AA50,0x1B255,0x06D20,0x0ADA0,
  129. x14B63
  130. };
  131.  
  132. #endregion
  133.  
  134. #region 星座名称
  135. private static string[] _constellationName =
  136. {
  137. "白羊座", "金牛座", "双子座",
  138. "巨蟹座", "狮子座", "处女座",
  139. "天秤座", "天蝎座", "射手座",
  140. "摩羯座", "水瓶座", "双鱼座"
  141. };
  142. #endregion
  143.  
  144. #region 二十四节气
  145. private static string[] _lunarHolidayName =
  146. {
  147. "小寒", "大寒", "立春", "雨水",
  148. "惊蛰", "春分", "清明", "谷雨",
  149. "立夏", "小满", "芒种", "夏至",
  150. "小暑", "大暑", "立秋", "处暑",
  151. "白露", "秋分", "寒露", "霜降",
  152. "立冬", "小雪", "大雪", "冬至"
  153. };
  154. #endregion
  155.  
  156. #region 二十八星宿
  157. private static string[] _chineseConstellationName =
  158. {
  159. //四 五 六 日 一 二 三
  160. "角木蛟","亢金龙","女土蝠","房日兔","心月狐","尾火虎","箕水豹",
  161. "斗木獬","牛金牛","氐土貉","虚日鼠","危月燕","室火猪","壁水獝",
  162. "奎木狼","娄金狗","胃土彘","昴日鸡","毕月乌","觜火猴","参水猿",
  163. "井木犴","鬼金羊","柳土獐","星日马","张月鹿","翼火蛇","轸水蚓"
  164. };
  165. #endregion
  166.  
  167. #region 节气数据
  168. private static string[] SolarTerm = new string[] { "小寒", "大寒", "立春", "雨水", "惊蛰", "春分", "清明", "谷雨", "立夏", "小满", "芒种", "夏至", "小暑", "大暑", "立秋", "处暑", "白露", "秋分", "寒露", "霜降", "立冬", "小雪", "大雪", "冬至" };
  169. private static int[] sTermInfo = new int[] { , , , , , , , , , , , , , , , , , , , , , , , };
  170. #endregion
  171.  
  172. #region 农历相关数据
  173. private static string ganStr = "甲乙丙丁戊己庚辛壬癸";
  174. private static string zhiStr = "子丑寅卯辰巳午未申酉戌亥";
  175. private static string animalStr = "鼠牛虎兔龙蛇马羊猴鸡狗猪";
  176. private static string nStr1 = "日一二三四五六七八九";
  177. private static string nStr2 = "初十廿卅";
  178. private static string[] _monthString =
  179. {
  180. "出错","正月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","腊月"
  181. };
  182. #endregion
  183.  
  184. #region 按公历计算的节日
  185. private static SolarHolidayStruct[] sHolidayInfo = new SolarHolidayStruct[]{
  186. new SolarHolidayStruct(, , , "元旦"),
  187. new SolarHolidayStruct(, , , "世界湿地日"),
  188. new SolarHolidayStruct(, , , "国际气象节"),
  189. new SolarHolidayStruct(, , , "情人节"),
  190. new SolarHolidayStruct(, , , "国际海豹日"),
  191. new SolarHolidayStruct(, , , "学雷锋纪念日"),
  192. new SolarHolidayStruct(, , , "妇女节"),
  193. new SolarHolidayStruct(, , , "植树节 孙中山逝世纪念日"),
  194. new SolarHolidayStruct(, , , "国际警察日"),
  195. new SolarHolidayStruct(, , , "消费者权益日"),
  196. new SolarHolidayStruct(, , , "中国国医节 国际航海日"),
  197. new SolarHolidayStruct(, , , "世界森林日 消除种族歧视国际日 世界儿歌日"),
  198. new SolarHolidayStruct(, , , "世界水日"),
  199. new SolarHolidayStruct(, , , "世界防治结核病日"),
  200. new SolarHolidayStruct(, , , "愚人节"),
  201. new SolarHolidayStruct(, , , "世界卫生日"),
  202. new SolarHolidayStruct(, , , "世界地球日"),
  203. new SolarHolidayStruct(, , , "劳动节"),
  204. new SolarHolidayStruct(, , , "劳动节假日"),
  205. new SolarHolidayStruct(, , , "劳动节假日"),
  206. new SolarHolidayStruct(, , , "青年节"),
  207. new SolarHolidayStruct(, , , "世界红十字日"),
  208. new SolarHolidayStruct(, , , "国际护士节"),
  209. new SolarHolidayStruct(, , , "世界无烟日"),
  210. new SolarHolidayStruct(, , , "国际儿童节"),
  211. new SolarHolidayStruct(, , , "世界环境保护日"),
  212. new SolarHolidayStruct(, , , "国际禁毒日"),
  213. new SolarHolidayStruct(, , , "建党节 香港回归纪念 世界建筑日"),
  214. new SolarHolidayStruct(, , , "世界人口日"),
  215. new SolarHolidayStruct(, , , "建军节"),
  216. new SolarHolidayStruct(, , , "中国男子节 父亲节"),
  217. new SolarHolidayStruct(, , , "抗日战争胜利纪念"),
  218. new SolarHolidayStruct(, , , " 逝世纪念"),
  219. new SolarHolidayStruct(, , , "教师节"),
  220. new SolarHolidayStruct(, , , "九·一八事变纪念日"),
  221. new SolarHolidayStruct(, , , "国际爱牙日"),
  222. new SolarHolidayStruct(, , , "世界旅游日"),
  223. new SolarHolidayStruct(, , , "孔子诞辰"),
  224. new SolarHolidayStruct(, , , "国庆节 国际音乐日"),
  225. new SolarHolidayStruct(, , , "国庆节假日"),
  226. new SolarHolidayStruct(, , , "国庆节假日"),
  227. new SolarHolidayStruct(, , , "老人节"),
  228. new SolarHolidayStruct(, , , "联合国日"),
  229. new SolarHolidayStruct(, , , "世界青年节"),
  230. new SolarHolidayStruct(, , , "孙中山诞辰纪念"),
  231. new SolarHolidayStruct(, , , "世界艾滋病日"),
  232. new SolarHolidayStruct(, , , "世界残疾人日"),
  233. new SolarHolidayStruct(, , , "澳门回归纪念"),
  234. new SolarHolidayStruct(, , , "平安夜"),
  235. new SolarHolidayStruct(, , , "圣诞节"),
  236. new SolarHolidayStruct(, , , " 诞辰纪念")
  237. };
  238. #endregion
  239.  
  240. #region 按农历计算的节日
  241. private static LunarHolidayStruct[] lHolidayInfo = new LunarHolidayStruct[]{
  242. new LunarHolidayStruct(, , , "春节"),
  243. new LunarHolidayStruct(, , , "元宵节"),
  244. new LunarHolidayStruct(, , , "端午节"),
  245. new LunarHolidayStruct(, , , "七夕情人节"),
  246. new LunarHolidayStruct(, , , "中元节 盂兰盆节"),
  247. new LunarHolidayStruct(, , , "中秋节"),
  248. new LunarHolidayStruct(, , , "重阳节"),
  249. new LunarHolidayStruct(, , , "腊八节"),
  250. new LunarHolidayStruct(, , , "北方小年(扫房)"),
  251. new LunarHolidayStruct(, , , "南方小年(掸尘)"),
  252. //new LunarHolidayStruct(12, 30, 0, "除夕") //注意除夕需要其它方法进行计算
  253. };
  254. #endregion
  255.  
  256. #region 按某月第几个星期几
  257. private static WeekHolidayStruct[] wHolidayInfo = new WeekHolidayStruct[]{
  258. new WeekHolidayStruct(, , , "母亲节"),
  259. new WeekHolidayStruct(, , , "全国助残日"),
  260. new WeekHolidayStruct(, , , "父亲节"),
  261. new WeekHolidayStruct(, , , "国际和平日"),
  262. new WeekHolidayStruct(, , , "国际聋人节"),
  263. new WeekHolidayStruct(, , , "国际住房日"),
  264. new WeekHolidayStruct(, , , "国际减轻自然灾害日"),
  265. new WeekHolidayStruct(, , , "感恩节")
  266. };
  267. #endregion
  268.  
  269. #endregion
  270.  
  271. #region 构造函数
  272. #region ChinaCalendar <公历日期初始化>
  273. /// <summary>
  274. /// 用一个标准的公历日期来初使化
  275. /// </summary>
  276. /// <param name="dt"></param>
  277. public ChineseCalendar(DateTime dt)
  278. {
  279. int i;
  280. int leap;
  281. int temp;
  282. int offset;
  283.  
  284. CheckDateLimit(dt);
  285.  
  286. _date = dt.Date;
  287. _datetime = dt;
  288.  
  289. //农历日期计算部分
  290. leap = ;
  291. temp = ;
  292.  
  293. TimeSpan ts = _date - ChineseCalendar.MinDay;//计算两天的基本差距
  294. offset = ts.Days;
  295.  
  296. for (i = MinYear; i <= MaxYear; i++)
  297. {
  298. temp = GetChineseYearDays(i); //求当年农历年天数
  299. if (offset - temp < )
  300. break;
  301. else
  302. {
  303. offset = offset - temp;
  304. }
  305. }
  306. _cYear = i;
  307.  
  308. leap = GetChineseLeapMonth(_cYear);//计算该年闰哪个月
  309. //设定当年是否有闰月
  310. if (leap > )
  311. {
  312. _cIsLeapYear = true;
  313. }
  314. else
  315. {
  316. _cIsLeapYear = false;
  317. }
  318.  
  319. _cIsLeapMonth = false;
  320. for (i = ; i <= ; i++)
  321. {
  322. //闰月
  323. if ((leap > ) && (i == leap + ) && (_cIsLeapMonth == false))
  324. {
  325. _cIsLeapMonth = true;
  326. i = i - ;
  327. temp = GetChineseLeapMonthDays(_cYear); //计算闰月天数
  328. }
  329. else
  330. {
  331. _cIsLeapMonth = false;
  332. temp = GetChineseMonthDays(_cYear, i);//计算非闰月天数
  333. }
  334.  
  335. offset = offset - temp;
  336. if (offset <= ) break;
  337. }
  338.  
  339. offset = offset + temp;
  340. _cMonth = i;
  341. _cDay = offset;
  342. }
  343. #endregion
  344.  
  345. #region ChinaCalendar <农历日期初始化>
  346. /// <summary>
  347. /// 用农历的日期来初使化
  348. /// </summary>
  349. /// <param name="cy">农历年</param>
  350. /// <param name="cm">农历月</param>
  351. /// <param name="cd">农历日</param>
  352. /// <param name="LeapFlag">闰月标志</param>
  353. public ChineseCalendar(int cy, int cm, int cd, bool leapMonthFlag)
  354. {
  355. int i, leap, Temp, offset;
  356.  
  357. CheckChineseDateLimit(cy, cm, cd, leapMonthFlag);
  358.  
  359. _cYear = cy;
  360. _cMonth = cm;
  361. _cDay = cd;
  362.  
  363. offset = ;
  364.  
  365. for (i = MinYear; i < cy; i++)
  366. {
  367. Temp = GetChineseYearDays(i); //求当年农历年天数
  368. offset = offset + Temp;
  369. }
  370.  
  371. leap = GetChineseLeapMonth(cy);// 计算该年应该闰哪个月
  372. if (leap != )
  373. {
  374. this._cIsLeapYear = true;
  375. }
  376. else
  377. {
  378. this._cIsLeapYear = false;
  379. }
  380.  
  381. if (cm != leap)
  382. {
  383. _cIsLeapMonth = false; //当前日期并非闰月
  384. }
  385. else
  386. {
  387. _cIsLeapMonth = leapMonthFlag; //使用用户输入的是否闰月月份
  388. }
  389.  
  390. if ((_cIsLeapYear == false) || //当年没有闰月
  391. (cm < leap)) //计算月份小于闰月
  392. {
  393. #region ...
  394. for (i = ; i < cm; i++)
  395. {
  396. Temp = GetChineseMonthDays(cy, i);//计算非闰月天数
  397. offset = offset + Temp;
  398. }
  399.  
  400. //检查日期是否大于最大天
  401. if (cd > GetChineseMonthDays(cy, cm))
  402. {
  403. throw new ChineseCalendarException("不合法的农历日期");
  404. }
  405. offset = offset + cd; //加上当月的天数
  406. #endregion
  407. }
  408. else //是闰年,且计算月份大于或等于闰月
  409. {
  410. #region ...
  411. for (i = ; i < cm; i++)
  412. {
  413. Temp = GetChineseMonthDays(cy, i); //计算非闰月天数
  414. offset = offset + Temp;
  415. }
  416.  
  417. if (cm > leap) //计算月大于闰月
  418. {
  419. Temp = GetChineseLeapMonthDays(cy); //计算闰月天数
  420. offset = offset + Temp; //加上闰月天数
  421.  
  422. if (cd > GetChineseMonthDays(cy, cm))
  423. {
  424. throw new ChineseCalendarException("不合法的农历日期");
  425. }
  426. offset = offset + cd;
  427. }
  428. else //计算月等于闰月
  429. {
  430. //如果需要计算的是闰月,则应首先加上与闰月对应的普通月的天数
  431. if (this._cIsLeapMonth == true) //计算月为闰月
  432. {
  433. Temp = GetChineseMonthDays(cy, cm); //计算非闰月天数
  434. offset = offset + Temp;
  435. }
  436.  
  437. if (cd > GetChineseLeapMonthDays(cy))
  438. {
  439. throw new ChineseCalendarException("不合法的农历日期");
  440. }
  441. offset = offset + cd;
  442. }
  443. #endregion
  444. }
  445.  
  446. _date = MinDay.AddDays(offset);
  447. }
  448. #endregion
  449. #endregion
  450.  
  451. #region 私有函数
  452.  
  453. #region GetChineseMonthDays
  454. //传回农历 y年m月的总天数
  455. private int GetChineseMonthDays(int year, int month)
  456. {
  457. if (BitTest32((LunarDateArray[year - MinYear] & 0x0000FFFF), ( - month)))
  458. {
  459. return ;
  460. }
  461. else
  462. {
  463. return ;
  464. }
  465. }
  466. #endregion
  467.  
  468. #region GetChineseLeapMonth
  469. //传回农历 y年闰哪个月 1-12 , 没闰传回 0
  470. private int GetChineseLeapMonth(int year)
  471. {
  472.  
  473. return LunarDateArray[year - MinYear] & 0xF;
  474.  
  475. }
  476. #endregion
  477.  
  478. #region GetChineseLeapMonthDays
  479. //传回农历 y年闰月的天数
  480. private int GetChineseLeapMonthDays(int year)
  481. {
  482. if (GetChineseLeapMonth(year) != )
  483. {
  484. if ((LunarDateArray[year - MinYear] & 0x10000) != )
  485. {
  486. return ;
  487. }
  488. else
  489. {
  490. return ;
  491. }
  492. }
  493. else
  494. {
  495. return ;
  496. }
  497. }
  498. #endregion
  499.  
  500. #region GetChineseYearDays
  501. /// <summary>
  502. /// 取农历年一年的天数
  503. /// </summary>
  504. /// <param name="year"></param>
  505. /// <returns></returns>
  506. private int GetChineseYearDays(int year)
  507. {
  508. int i, f, sumDay, info;
  509.  
  510. sumDay = ; //29天 X 12个月
  511. i = 0x8000;
  512. info = LunarDateArray[year - MinYear] & 0x0FFFF;
  513.  
  514. //计算12个月中有多少天为30天
  515. for (int m = ; m < ; m++)
  516. {
  517. f = info & i;
  518. if (f != )
  519. {
  520. sumDay++;
  521. }
  522. i = i >> ;
  523. }
  524. return sumDay + GetChineseLeapMonthDays(year);
  525. }
  526. #endregion
  527.  
  528. #region GetChineseHour
  529. /// <summary>
  530. /// 获得当前时间的时辰
  531. /// </summary>
  532. /// <param name="time"></param>
  533. /// <returns></returns>
  534. ///
  535. private string GetChineseHour(DateTime dt)
  536. {
  537.  
  538. int _hour, _minute, offset, i;
  539. int indexGan;
  540. string ganHour, zhiHour;
  541. string tmpGan;
  542.  
  543. //计算时辰的地支
  544. _hour = dt.Hour; //获得当前时间小时
  545. _minute = dt.Minute; //获得当前时间分钟
  546.  
  547. if (_minute != ) _hour += ;
  548. offset = _hour / ;
  549. if (offset >= ) offset = ;
  550. //zhiHour = zhiStr[offset].ToString();
  551.  
  552. //计算天干
  553. TimeSpan ts = this._date - GanZhiStartDay;
  554. i = ts.Days % ;
  555.  
  556. indexGan = ((i % + ) * - ) % - ; //ganStr[i % 10] 为日的天干,(n*2-1) %10得出地支对应,n从1开始
  557. tmpGan = ganStr.Substring(indexGan) + ganStr.Substring(, indexGan + );//凑齐12位
  558. //ganHour = ganStr[((i % 10 + 1) * 2 - 1) % 10 - 1].ToString();
  559.  
  560. return tmpGan[offset].ToString() + zhiStr[offset].ToString();
  561.  
  562. }
  563. #endregion
  564.  
  565. #region CheckDateLimit
  566. /// <summary>
  567. /// 检查公历日期是否符合要求
  568. /// </summary>
  569. /// <param name="dt"></param>
  570. private void CheckDateLimit(DateTime dt)
  571. {
  572. if ((dt < MinDay) || (dt > MaxDay))
  573. {
  574. throw new ChineseCalendarException("超出可转换的日期");
  575. }
  576. }
  577. #endregion
  578.  
  579. #region CheckChineseDateLimit
  580. /// <summary>
  581. /// 检查农历日期是否合理
  582. /// </summary>
  583. /// <param name="year"></param>
  584. /// <param name="month"></param>
  585. /// <param name="day"></param>
  586. /// <param name="leapMonth"></param>
  587. private void CheckChineseDateLimit(int year, int month, int day, bool leapMonth)
  588. {
  589. if ((year < MinYear) || (year > MaxYear))
  590. {
  591. throw new ChineseCalendarException("非法农历日期");
  592. }
  593. if ((month < ) || (month > ))
  594. {
  595. throw new ChineseCalendarException("非法农历日期");
  596. }
  597. if ((day < ) || (day > )) //中国的月最多30天
  598. {
  599. throw new ChineseCalendarException("非法农历日期");
  600. }
  601.  
  602. int leap = GetChineseLeapMonth(year);// 计算该年应该闰哪个月
  603. if ((leapMonth == true) && (month != leap))
  604. {
  605. throw new ChineseCalendarException("非法农历日期");
  606. }
  607.  
  608. }
  609. #endregion
  610.  
  611. #region ConvertNumToChineseNum
  612. /// <summary>
  613. /// 将0-9转成汉字形式
  614. /// </summary>
  615. /// <param name="n"></param>
  616. /// <returns></returns>
  617. private string ConvertNumToChineseNum(char n)
  618. {
  619. if ((n < '') || (n > '')) return "";
  620. switch (n)
  621. {
  622. case '':
  623. return HZNum[].ToString();
  624. case '':
  625. return HZNum[].ToString();
  626. case '':
  627. return HZNum[].ToString();
  628. case '':
  629. return HZNum[].ToString();
  630. case '':
  631. return HZNum[].ToString();
  632. case '':
  633. return HZNum[].ToString();
  634. case '':
  635. return HZNum[].ToString();
  636. case '':
  637. return HZNum[].ToString();
  638. case '':
  639. return HZNum[].ToString();
  640. case '':
  641. return HZNum[].ToString();
  642. default:
  643. return "";
  644. }
  645. }
  646. #endregion
  647.  
  648. #region BitTest32
  649. /// <summary>
  650. /// 测试某位是否为真
  651. /// </summary>
  652. /// <param name="num"></param>
  653. /// <param name="bitpostion"></param>
  654. /// <returns></returns>
  655. private bool BitTest32(int num, int bitpostion)
  656. {
  657.  
  658. if ((bitpostion > ) || (bitpostion < ))
  659. throw new Exception("Error Param: bitpostion[0-31]:" + bitpostion.ToString());
  660.  
  661. int bit = << bitpostion;
  662.  
  663. if ((num & bit) == )
  664. {
  665. return false;
  666. }
  667. else
  668. {
  669. return true;
  670. }
  671. }
  672. #endregion
  673.  
  674. #region ConvertDayOfWeek
  675. /// <summary>
  676. /// 将星期几转成数字表示
  677. /// </summary>
  678. /// <param name="dayOfWeek"></param>
  679. /// <returns></returns>
  680. private int ConvertDayOfWeek(DayOfWeek dayOfWeek)
  681. {
  682. switch (dayOfWeek)
  683. {
  684. case DayOfWeek.Sunday:
  685. return ;
  686. case DayOfWeek.Monday:
  687. return ;
  688. case DayOfWeek.Tuesday:
  689. return ;
  690. case DayOfWeek.Wednesday:
  691. return ;
  692. case DayOfWeek.Thursday:
  693. return ;
  694. case DayOfWeek.Friday:
  695. return ;
  696. case DayOfWeek.Saturday:
  697. return ;
  698. default:
  699. return ;
  700. }
  701. }
  702. #endregion
  703.  
  704. #region CompareWeekDayHoliday
  705. /// <summary>
  706. /// 比较当天是不是指定的第周几
  707. /// </summary>
  708. /// <param name="date"></param>
  709. /// <param name="month"></param>
  710. /// <param name="week"></param>
  711. /// <param name="day"></param>
  712. /// <returns></returns>
  713. private bool CompareWeekDayHoliday(DateTime date, int month, int week, int day)
  714. {
  715. bool ret = false;
  716.  
  717. if (date.Month == month) //月份相同
  718. {
  719. if (ConvertDayOfWeek(date.DayOfWeek) == day) //星期几相同
  720. {
  721. DateTime firstDay = new DateTime(date.Year, date.Month, );//生成当月第一天
  722. int i = ConvertDayOfWeek(firstDay.DayOfWeek);
  723. int firWeekDays = - ConvertDayOfWeek(firstDay.DayOfWeek) + ; //计算第一周剩余天数
  724.  
  725. if (i > day)
  726. {
  727. if ((week - ) * + day + firWeekDays == date.Day)
  728. {
  729. ret = true;
  730. }
  731. }
  732. else
  733. {
  734. if (day + firWeekDays + (week - ) * == date.Day)
  735. {
  736. ret = true;
  737. }
  738. }
  739. }
  740. }
  741.  
  742. return ret;
  743. }
  744. #endregion
  745. #endregion
  746.  
  747. #region 属性
  748.  
  749. #region 节日
  750. #region ChineseCalendarHoliday
  751. /// <summary>
  752. /// 计算中国农历节日
  753. /// </summary>
  754. public string ChineseCalendarHoliday
  755. {
  756. get
  757. {
  758. string tempStr = "";
  759. if (this._cIsLeapMonth == false) //闰月不计算节日
  760. {
  761. foreach (LunarHolidayStruct lh in lHolidayInfo)
  762. {
  763. if ((lh.Month == this._cMonth) && (lh.Day == this._cDay))
  764. {
  765.  
  766. tempStr = lh.HolidayName;
  767. break;
  768.  
  769. }
  770. }
  771.  
  772. //对除夕进行特别处理
  773. if (this._cMonth == )
  774. {
  775. int i = GetChineseMonthDays(this._cYear, ); //计算当年农历12月的总天数
  776. if (this._cDay == i) //如果为最后一天
  777. {
  778. tempStr = "除夕";
  779. }
  780. }
  781. }
  782. return tempStr;
  783. }
  784. }
  785. #endregion
  786.  
  787. #region WeekDayHoliday
  788. /// <summary>
  789. /// 按某月第几周第几日计算的节日
  790. /// </summary>
  791. public string WeekDayHoliday
  792. {
  793. get
  794. {
  795. string tempStr = "";
  796. foreach (WeekHolidayStruct wh in wHolidayInfo)
  797. {
  798. if (CompareWeekDayHoliday(_date, wh.Month, wh.WeekAtMonth, wh.WeekDay))
  799. {
  800. tempStr = wh.HolidayName;
  801. break;
  802. }
  803. }
  804. return tempStr;
  805. }
  806. }
  807. #endregion
  808.  
  809. #region DateHoliday
  810. /// <summary>
  811. /// 按公历日计算的节日
  812. /// </summary>
  813. public string DateHoliday
  814. {
  815. get
  816. {
  817. string tempStr = "";
  818.  
  819. foreach (SolarHolidayStruct sh in sHolidayInfo)
  820. {
  821. if ((sh.Month == _date.Month) && (sh.Day == _date.Day))
  822. {
  823. tempStr = sh.HolidayName;
  824. break;
  825. }
  826. }
  827. return tempStr;
  828. }
  829. }
  830. #endregion
  831. #endregion
  832.  
  833. #region 公历日期
  834. #region Date
  835. /// <summary>
  836. /// 取对应的公历日期
  837. /// </summary>
  838. public DateTime Date
  839. {
  840. get { return _date; }
  841. set { _date = value; }
  842. }
  843. #endregion
  844.  
  845. #region WeekDay
  846. /// <summary>
  847. /// 取星期几
  848. /// </summary>
  849. public DayOfWeek WeekDay
  850. {
  851. get { return _date.DayOfWeek; }
  852. }
  853. #endregion
  854.  
  855. #region WeekDayStr
  856. /// <summary>
  857. /// 周几的字符
  858. /// </summary>
  859. public string WeekDayStr
  860. {
  861. get
  862. {
  863. switch (_date.DayOfWeek)
  864. {
  865. case DayOfWeek.Sunday:
  866. return "星期日";
  867. case DayOfWeek.Monday:
  868. return "星期一";
  869. case DayOfWeek.Tuesday:
  870. return "星期二";
  871. case DayOfWeek.Wednesday:
  872. return "星期三";
  873. case DayOfWeek.Thursday:
  874. return "星期四";
  875. case DayOfWeek.Friday:
  876. return "星期五";
  877. default:
  878. return "星期六";
  879. }
  880. }
  881. }
  882. #endregion
  883.  
  884. #region DateString
  885. /// <summary>
  886. /// 公历日期中文表示法 如一九九七年七月一日
  887. /// </summary>
  888. public string DateString
  889. {
  890. get
  891. {
  892. return "公元" + this._date.ToLongDateString();
  893. }
  894. }
  895. #endregion
  896.  
  897. #region IsLeapYear
  898. /// <summary>
  899. /// 当前是否公历闰年
  900. /// </summary>
  901. public bool IsLeapYear
  902. {
  903. get
  904. {
  905. return DateTime.IsLeapYear(this._date.Year);
  906. }
  907. }
  908. #endregion
  909.  
  910. #region ChineseConstellation
  911. /// <summary>
  912. /// 28星宿计算
  913. /// </summary>
  914. public string ChineseConstellation
  915. {
  916. get
  917. {
  918. int offset = ;
  919. int modStarDay = ;
  920.  
  921. TimeSpan ts = this._date - ChineseConstellationReferDay;
  922. offset = ts.Days;
  923. modStarDay = offset % ;
  924. return (modStarDay >= ? _chineseConstellationName[modStarDay] : _chineseConstellationName[ + modStarDay]);
  925. }
  926. }
  927. #endregion
  928.  
  929. #region ChineseHour
  930. /// <summary>
  931. /// 时辰
  932. /// </summary>
  933. public string ChineseHour
  934. {
  935. get
  936. {
  937. return GetChineseHour(_datetime);
  938. }
  939. }
  940. #endregion
  941.  
  942. #endregion
  943.  
  944. #region 农历日期
  945. #region IsChineseLeapMonth
  946. /// <summary>
  947. /// 是否闰月
  948. /// </summary>
  949. public bool IsChineseLeapMonth
  950. {
  951. get { return this._cIsLeapMonth; }
  952. }
  953. #endregion
  954.  
  955. #region IsChineseLeapYear
  956. /// <summary>
  957. /// 当年是否有闰月
  958. /// </summary>
  959. public bool IsChineseLeapYear
  960. {
  961. get
  962. {
  963. return this._cIsLeapYear;
  964. }
  965. }
  966. #endregion
  967.  
  968. #region ChineseDay
  969. /// <summary>
  970. /// 农历日
  971. /// </summary>
  972. public int ChineseDay
  973. {
  974. get { return this._cDay; }
  975. }
  976. #endregion
  977.  
  978. #region ChineseDayString
  979. /// <summary>
  980. /// 农历日中文表示
  981. /// </summary>
  982. public string ChineseDayString
  983. {
  984. get
  985. {
  986. switch (this._cDay)
  987. {
  988. case :
  989. return "";
  990. case :
  991. return "初十";
  992. case :
  993. return "二十";
  994. case :
  995. return "三十";
  996. default:
  997. return nStr2[(int)(_cDay / )].ToString() + nStr1[_cDay % ].ToString();
  998.  
  999. }
  1000. }
  1001. }
  1002. #endregion
  1003.  
  1004. #region ChineseMonth
  1005. /// <summary>
  1006. /// 农历的月份
  1007. /// </summary>
  1008. public int ChineseMonth
  1009. {
  1010. get { return this._cMonth; }
  1011. }
  1012. #endregion
  1013.  
  1014. #region ChineseMonthString
  1015. /// <summary>
  1016. /// 农历月份字符串
  1017. /// </summary>
  1018. public string ChineseMonthString
  1019. {
  1020. get
  1021. {
  1022. return _monthString[this._cMonth];
  1023. }
  1024. }
  1025. #endregion
  1026.  
  1027. #region ChineseYear
  1028. /// <summary>
  1029. /// 取农历年份
  1030. /// </summary>
  1031. public int ChineseYear
  1032. {
  1033. get { return this._cYear; }
  1034. }
  1035. #endregion
  1036.  
  1037. #region ChineseYearString
  1038. /// <summary>
  1039. /// 取农历年字符串如,一九九七年
  1040. /// </summary>
  1041. public string ChineseYearString
  1042. {
  1043. get
  1044. {
  1045. string tempStr = "";
  1046. string num = this._cYear.ToString();
  1047. for (int i = ; i < ; i++)
  1048. {
  1049. tempStr += ConvertNumToChineseNum(num[i]);
  1050. }
  1051. return tempStr + "年";
  1052. }
  1053. }
  1054. #endregion
  1055.  
  1056. #region ChineseDateString
  1057. /// <summary>
  1058. /// 取农历日期表示法:农历一九九七年正月初五
  1059. /// </summary>
  1060. public string ChineseDateString
  1061. {
  1062. get
  1063. {
  1064. if (this._cIsLeapMonth == true)
  1065. {
  1066. return "农历" + ChineseYearString + "闰" + ChineseMonthString + ChineseDayString;
  1067. }
  1068. else
  1069. {
  1070. return "农历" + ChineseYearString + ChineseMonthString + ChineseDayString;
  1071. }
  1072. }
  1073. }
  1074. #endregion
  1075.  
  1076. #region ChineseTwentyFourDay
  1077. /// <summary>
  1078. /// 定气法计算二十四节气,二十四节气是按地球公转来计算的,并非是阴历计算的
  1079. /// </summary>
  1080. /// <remarks>
  1081. /// 节气的定法有两种。古代历法采用的称为"恒气",即按时间把一年等分为24份,
  1082. /// 每一节气平均得15天有余,所以又称"平气"。现代农历采用的称为"定气",即
  1083. /// 按地球在轨道上的位置为标准,一周360°,两节气之间相隔15°。由于冬至时地
  1084. /// 球位于近日点附近,运动速度较快,因而太阳在黄道上移动15°的时间不到15天。
  1085. /// 夏至前后的情况正好相反,太阳在黄道上移动较慢,一个节气达16天之多。采用
  1086. /// 定气时可以保证春、秋两分必然在昼夜平分的那两天。
  1087. /// </remarks>
  1088. public string ChineseTwentyFourDay
  1089. {
  1090. get
  1091. {
  1092. DateTime baseDateAndTime = new DateTime(, , , , , ); //#1/6/1900 2:05:00 AM#
  1093. DateTime newDate;
  1094. double num;
  1095. int y;
  1096. string tempStr = "";
  1097.  
  1098. y = this._date.Year;
  1099.  
  1100. for (int i = ; i <= ; i++)
  1101. {
  1102. num = 525948.76 * (y - ) + sTermInfo[i - ];
  1103.  
  1104. newDate = baseDateAndTime.AddMinutes(num);//按分钟计算
  1105. if (newDate.DayOfYear == _date.DayOfYear)
  1106. {
  1107. tempStr = SolarTerm[i - ];
  1108. break;
  1109. }
  1110. }
  1111. return tempStr;
  1112. }
  1113. }
  1114.  
  1115. //当前日期前一个最近节气
  1116. public string ChineseTwentyFourPrevDay
  1117. {
  1118. get
  1119. {
  1120. DateTime baseDateAndTime = new DateTime(, , , , , ); //#1/6/1900 2:05:00 AM#
  1121. DateTime newDate;
  1122. double num;
  1123. int y;
  1124. string tempStr = "";
  1125.  
  1126. y = this._date.Year;
  1127.  
  1128. for (int i = ; i >= ; i--)
  1129. {
  1130. num = 525948.76 * (y - ) + sTermInfo[i - ];
  1131.  
  1132. newDate = baseDateAndTime.AddMinutes(num);//按分钟计算
  1133.  
  1134. if (newDate.DayOfYear < _date.DayOfYear)
  1135. {
  1136. tempStr = string.Format("{0}[{1}]", SolarTerm[i - ], newDate.ToString("yyyy-MM-dd"));
  1137. break;
  1138. }
  1139. }
  1140.  
  1141. return tempStr;
  1142. }
  1143.  
  1144. }
  1145.  
  1146. //当前日期后一个最近节气
  1147. public string ChineseTwentyFourNextDay
  1148. {
  1149. get
  1150. {
  1151. DateTime baseDateAndTime = new DateTime(, , , , , ); //#1/6/1900 2:05:00 AM#
  1152. DateTime newDate;
  1153. double num;
  1154. int y;
  1155. string tempStr = "";
  1156.  
  1157. y = this._date.Year;
  1158.  
  1159. for (int i = ; i <= ; i++)
  1160. {
  1161. num = 525948.76 * (y - ) + sTermInfo[i - ];
  1162.  
  1163. newDate = baseDateAndTime.AddMinutes(num);//按分钟计算
  1164.  
  1165. if (newDate.DayOfYear > _date.DayOfYear)
  1166. {
  1167. tempStr = string.Format("{0}[{1}]", SolarTerm[i - ], newDate.ToString("yyyy-MM-dd"));
  1168. break;
  1169. }
  1170. }
  1171. return tempStr;
  1172. }
  1173.  
  1174. }
  1175. #endregion
  1176. #endregion
  1177.  
  1178. #region 星座
  1179. #region Constellation
  1180. /// <summary>
  1181. /// 计算指定日期的星座序号
  1182. /// </summary>
  1183. /// <returns></returns>
  1184. public string Constellation
  1185. {
  1186. get
  1187. {
  1188. int index = ;
  1189. int y, m, d;
  1190. y = _date.Year;
  1191. m = _date.Month;
  1192. d = _date.Day;
  1193. y = m * + d;
  1194.  
  1195. if (((y >= ) && (y <= ))) { index = ; }
  1196. else if ((y >= ) && (y <= )) { index = ; }
  1197. else if ((y >= ) && (y <= )) { index = ; }
  1198. else if ((y >= ) && (y <= )) { index = ; }
  1199. else if ((y >= ) && (y <= )) { index = ; }
  1200. else if ((y >= ) && (y <= )) { index = ; }
  1201. else if ((y >= ) && (y <= )) { index = ; }
  1202. else if ((y >= ) && (y <= )) { index = ; }
  1203. else if ((y >= ) && (y <= )) { index = ; }
  1204. else if ((y >= ) || (y <= )) { index = ; }
  1205. else if ((y >= ) && (y <= )) { index = ; }
  1206. else if ((y >= ) && (y <= )) { index = ; }
  1207. else { index = ; }
  1208.  
  1209. return _constellationName[index];
  1210. }
  1211. }
  1212. #endregion
  1213. #endregion
  1214.  
  1215. #region 属相
  1216. #region Animal
  1217. /// <summary>
  1218. /// 计算属相的索引,注意虽然属相是以农历年来区别的,但是目前在实际使用中是按公历来计算的
  1219. /// 鼠年为1,其它类推
  1220. /// </summary>
  1221. public int Animal
  1222. {
  1223. get
  1224. {
  1225. int offset = _date.Year - AnimalStartYear;
  1226. return (offset % ) + ;
  1227. }
  1228. }
  1229. #endregion
  1230.  
  1231. #region AnimalString
  1232. /// <summary>
  1233. /// 取属相字符串
  1234. /// </summary>
  1235. public string AnimalString
  1236. {
  1237. get
  1238. {
  1239. int offset = _date.Year - AnimalStartYear; //阳历计算
  1240. //int offset = this._cYear - AnimalStartYear; 农历计算
  1241. return animalStr[offset % ].ToString();
  1242. }
  1243. }
  1244. #endregion
  1245. #endregion
  1246.  
  1247. #region 天干地支
  1248. #region GanZhiYearString
  1249. /// <summary>
  1250. /// 取农历年的干支表示法如 乙丑年
  1251. /// </summary>
  1252. public string GanZhiYearString
  1253. {
  1254. get
  1255. {
  1256. string tempStr;
  1257. int i = (this._cYear - GanZhiStartYear) % ; //计算干支
  1258. tempStr = ganStr[i % ].ToString() + zhiStr[i % ].ToString() + "年";
  1259. return tempStr;
  1260. }
  1261. }
  1262. #endregion
  1263.  
  1264. #region GanZhiMonthString
  1265. /// <summary>
  1266. /// 取干支的月表示字符串,注意农历的闰月不记干支
  1267. /// </summary>
  1268. public string GanZhiMonthString
  1269. {
  1270. get
  1271. {
  1272. //每个月的地支总是固定的,而且总是从寅月开始
  1273. int zhiIndex;
  1274. string zhi;
  1275. if (this._cMonth > )
  1276. {
  1277. zhiIndex = this._cMonth - ;
  1278. }
  1279. else
  1280. {
  1281. zhiIndex = this._cMonth + ;
  1282. }
  1283. zhi = zhiStr[zhiIndex - ].ToString();
  1284.  
  1285. //根据当年的干支年的干来计算月干的第一个
  1286. int ganIndex = ;
  1287. string gan;
  1288. int i = (this._cYear - GanZhiStartYear) % ; //计算干支
  1289. switch (i % )
  1290. {
  1291. #region ...
  1292. case : //甲
  1293. ganIndex = ;
  1294. break;
  1295. case : //乙
  1296. ganIndex = ;
  1297. break;
  1298. case : //丙
  1299. ganIndex = ;
  1300. break;
  1301. case : //丁
  1302. ganIndex = ;
  1303. break;
  1304. case : //戊
  1305. ganIndex = ;
  1306. break;
  1307. case : //己
  1308. ganIndex = ;
  1309. break;
  1310. case : //庚
  1311. ganIndex = ;
  1312. break;
  1313. case : //辛
  1314. ganIndex = ;
  1315. break;
  1316. case : //壬
  1317. ganIndex = ;
  1318. break;
  1319. case : //癸
  1320. ganIndex = ;
  1321. break;
  1322. #endregion
  1323. }
  1324. gan = ganStr[(ganIndex + this._cMonth - ) % ].ToString();
  1325.  
  1326. return gan + zhi + "月";
  1327. }
  1328. }
  1329. #endregion
  1330.  
  1331. #region GanZhiDayString
  1332. /// <summary>
  1333. /// 取干支日表示法
  1334. /// </summary>
  1335. public string GanZhiDayString
  1336. {
  1337. get
  1338. {
  1339. int i, offset;
  1340. TimeSpan ts = this._date - GanZhiStartDay;
  1341. offset = ts.Days;
  1342. i = offset % ;
  1343. return ganStr[i % ].ToString() + zhiStr[i % ].ToString() + "日";
  1344. }
  1345. }
  1346. #endregion
  1347.  
  1348. #region GanZhiDateString
  1349. /// <summary>
  1350. /// 取当前日期的干支表示法如 甲子年乙丑月丙庚日
  1351. /// </summary>
  1352. public string GanZhiDateString
  1353. {
  1354. get
  1355. {
  1356. return GanZhiYearString + GanZhiMonthString + GanZhiDayString;
  1357. }
  1358. }
  1359. #endregion
  1360. #endregion
  1361. #endregion
  1362.  
  1363. #region 方法
  1364. #region NextDay
  1365. /// <summary>
  1366. /// 取下一天
  1367. /// </summary>
  1368. /// <returns></returns>
  1369. public ChineseCalendar NextDay()
  1370. {
  1371. DateTime nextDay = _date.AddDays();
  1372. return new ChineseCalendar(nextDay);
  1373. }
  1374. #endregion
  1375.  
  1376. #region PervDay
  1377. /// <summary>
  1378. /// 取前一天
  1379. /// </summary>
  1380. /// <returns></returns>
  1381. public ChineseCalendar PervDay()
  1382. {
  1383. DateTime pervDay = _date.AddDays(-);
  1384. return new ChineseCalendar(pervDay);
  1385. }
  1386. #endregion
  1387. #endregion
  1388. }
  1389. }

调用:

DateTime dt = DateTime.Now;
ChineseCalendar cc = new ChineseCalendar(dt);
Console.WriteLine("阳历:" + cc.DateString);
Console.WriteLine("属相:" + cc.AnimalString);
Console.WriteLine("农历:" + cc.ChineseDateString);
Console.WriteLine("时辰:" + cc.ChineseHour);
Console.WriteLine("节气:" + cc.ChineseTwentyFourDay);
Console.WriteLine("节日:" + cc.DateHoliday);
Console.WriteLine("前一个节气:" + cc.ChineseTwentyFourPrevDay);
Console.WriteLine("后一个节气:" + cc.ChineseTwentyFourNextDay);
Console.WriteLine("干支:" + cc.GanZhiDateString);
Console.WriteLine("星期:" + cc.WeekDayStr);
Console.WriteLine("星宿:" + cc.ChineseConstellation);
Console.WriteLine("星座:" + cc.Constellation);

结果:

阳历:公元2013年1月27日
属相:蛇
农历:农历二零一二年腊月十六
时辰:庚申
节气:
节日:
前一个节气:大寒[--]
后一个节气:立春[--]
干支:壬辰年癸丑月癸巳日
星期:星期日
星宿:房日兔
星座:水瓶座

C#实现万年历(农历、节气、节日、星座、属相、生肖、闰年等)的更多相关文章

  1. C#实现万年历(农历、节气、节日、星座、星宿、属相、生肖、闰年月、时辰)

    C# 万年历 农历 节气 节日 星座 星宿 属相 生肖 闰年月 时辰地址:http://www.cnblogs.com/txw1958/archive/2013/01/27/csharp-calend ...

  2. php获取农历、节日、节气

    /* * 农历 节气 节日 * edit: www.jbxue.com */ header("Content-Type:text/html;charset=utf-8"); cla ...

  3. FullCalendar应用——整合农历节气和节日

    FullCalendar用来做日程管理功能非常强大,但是唯一不足的地方是没有将中国农历历法加进去,今天我将结合实例和大家分享如何将中国农历中的节气和节日整合到FullCalendar中,从而增强其实用 ...

  4. Google日历添加农历、节日和天气插件(步骤)

    Google日历添加农历.节日和天气插件(步骤) Google功能非常多,Google日历只是其中一个,而且支持Exchange账户(iPhone,WP7,诺基亚等)和Google账户登录(andro ...

  5. php 身份证号码获取星座和生肖

    发布:thatboy   来源:Net     [大 中 小] 本文介绍下,php用身份证号码获取星座和生肖的方法,一个简单的php实例,从身份证号码中取得星座与生肖信息,有兴趣的朋友参考研究下吧.本 ...

  6. c#实现万年历示例分享 万年历农历查询

    cs.cs(类页面) using System;using System.Collections.Generic;using System.Linq;using System.Web; namespa ...

  7. PHP根据身份证号码验证、获取星座、生肖和性别函数

    首先介绍一下身份证含义 新的18位身份证号码各位的含义:1-2位省.自治区.直辖市代码:3-4位地级市.盟.自治州代码:5-6位县.县级市.区代码:7-14位出生年月日,比如19670401代表196 ...

  8. 推荐一款万年历App 诸葛万年历

    推荐一款万年历App 诸葛万年历 1 介绍 应用简介: 提供标准和专业的时间信息查询,记录和承载生活中的美好记忆,帮助用户高效快捷的管理个人时间.精美的日期展示和完善的重要事件提醒功能,可以方便安排日 ...

  9. 公历转农历的python实现

    大杂烩.作为自己的记录,保存. 两个要点: 1.公历转农历用了查表法(第126行) 2.节气用了天文法?(第176行)  运行图 (背景是hao123万年历) 源代码: # lunar.py # 20 ...

随机推荐

  1. LOTUS 迁移到Exchange 2010 POC 之在Exchange 2007 安装Lotus Admin!

    双击Setup安装:

  2. Spring4.0+Hibernate4.0+Struts2.3整合包括增删改查案例,解决整合中出现的异常

    源码下载:http://download.csdn.net/detail/cmcc_1234/7034775 ======================Application.xml======== ...

  3. J2EE项目相对路径、绝对路径获取

    String path = getServletContext().getRealPath("/"); 这将获取web项目的全路径. this.getClass().getClas ...

  4. Eclipse设置、调优、使用

    eclipse调优 一般在不对eclipse进行相关设置的时候,使用eclipse总是会觉得启动好慢,用起来好卡,其实只要对eclipse的相关参数进行一些配置,就会有很大的改善. 加快启动速度 1. ...

  5. [Sparrow OS 设计文档连载(一)] Introduction

  6. 一个python

    #!/usr/bin/env python #coding=utf-8 import os # 遍历文件 r=input("type a directory name:") for ...

  7. android 开源 + 一些素材网站

    ui 设计工具:http://www.sketchcn.com/ 分类汇总: https://github.com/Trinea/android-open-project 直接拿来用!最火的Andro ...

  8. 压力测试工具:tsung

    http://tsung.erlang-projects.org/user_manual/introduction.html#what-is-tsung

  9. 记录一点自己写的Php代码(1)取得任意种类,无限级下线

    //获取所有下线 function get_all_heeler($user_id,$user_rank = 0){ $user_id_array = $user_id; while (true) { ...

  10. SAE J1708 DS36277 MAX3444, DS75176B

    http://en.wikipedia.org/wiki/J1708 J1708 SAE J1708 is a standard used for serial communications betw ...