龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > JAVA开发 >

JAVA实例 阴阳历算法

时间:2009-12-23 15:42来源:未知 作者:admin 点击:
分享到:
程序为: /* 西历农历转换程式 黄晓鸣 1995,7,25 prototype: int calconv( strUCt convdate * ); struct convdate { int source; ==0 则输入日期为西历, !=0 则输入为农历 int solaryear; 输出或输入之西历年份 int s

程序为:
  /*
  
  西历农历转换程式 黄晓鸣 1995,7,25
  
  prototype: int calconv( strUCt convdate * );
  
  struct convdate
  {
   int source; ==0 则输入日期为西历, !=0 则输入为农历
   int solaryear; 输出或输入之西历年份
   int solarmonth; 西历月
   int solardate; 西历日
   int lunaryear; 输出或输入之农历年份
   int lunarmonth; 农历月
   int lunardate; 农历日
   int weekday; 该日为星期几 ( 0==星期日, 1==星期一, ... )
   int kan; 该日天干 ( 0==甲, 1==乙, ..., 9==癸 )
   int chih; 该日地支 ( 0==子, 1==丑, ..., 11==亥 )
  };
  
  呼叫时须设定 souce 的值, 若为 0 则为西历转农历, 否则为农历转西历. 然後视
  输入为西历或农历来设定西历或农历的年月日. 转换後的年月日会填入结构中( 农
  历或西历 ), 以及该日为星期几, 天干地支.
  若函式的返回值为 0 表示没有错误, 1 为输入之年份错误, 2 为输入之月份错误,
  3 为输入之日期错误.
  输入之西历年须在 1937 - 2031 间
  输入之农历年须在 1936 - 2030 间
  若须扩充, 则增加 lunarcal[]
  
  */
  
  #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; /* 到西历 1 月 1 日到农历正月初一的累积日数 */
   int intercalation; /* 闰月月份. 0==此年没有闰月 */
   int baseweekday; /* 此年西历 1 月 1 日为星期几再减 1 */
   int basekanchih; /* 此年西历 1 月 1 日之干支序号减 1 */
   int monthdays[13]; /* 此农历年每月之大小, 0==小月(29日), 1==大月(30日)*/
  };
  
  struct taglunarcal lunarcal[] = {
  { 23, 3, 2, 17, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0 }, /* 1936 */
  { 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 }, /* 1940 */
  { 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, 1, 0, 1, 0, 1, 1, 0, 1, 1 }, /* 1944 */
  { 43, 0, 0, 5, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1 },
  { 32, 0, 1, 10, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1 },
  { 21, 2, 2, 15, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1 },
  { 40, 0, 3, 20, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1 }, /* 1948 */
  { 28, 7, 5, 26, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 },
  { 47, 0, 6, 31, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1 },
  { 36, 0, 0, 36, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 },
  

精彩图集

赞助商链接