CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Java >  J2SE / 基础类

跪求各位大大,用java程序写出农历?不回答,我就不起来了-_-!

楼主zhanshengkui()2006-12-01 19:47:44 在 Java / J2SE / 基础类 提问

.. 问题点数:100、回复次数:13Top

1 楼s_topman(SQL love Linux! : ))回复于 2006-12-01 19:57:31 得分 0

起来吧,百度去Top

2 楼bengezhao(benge)回复于 2006-12-01 19:57:52 得分 0

搜索一下JAVASCRIPT   的代码,改改不就行了.Top

3 楼Chinajash()回复于 2006-12-01 19:59:14 得分 0

http://blog.csdn.net/peter207/archive/2006/06/28/845064.aspxTop

4 楼zh029t(蓝色海岸)回复于 2006-12-01 20:29:17 得分 0

//文件CalendarConvert.cpp        
           
      #include       "stdafx.h"        
      #include       "CalendarConvert.h"        
           
           
      /***************                   本类调用规则                   ******************        
      ******************************************************        
           
      1.   使用下面的函数来制作日历结构        
      MakeCalendar(CALENDAR       *m_cal,int       y,int       m,int       d);//填充日期结构的年月日        
           
      2.   使用本函数来检验日历是否合法        
      BOOL       GongDataIsValid(CALENDAR       m_date);               //判断公历日期是否在界内        
      BOOL       NongDataIsValid(CALENDAR       m_date);               //判断农历日期是否在界内        
           
      3.               将合法日历进行公农历相互转换        
      CALENDAR       ConvertToGongLi(CALENDAR       m_nongli);               //将农历日期转化为公历日期        
      CALENDAR       ConvertToNongLi(CALENDAR       m_gongli);               //将公历日期转化为农历日期        
           
      4.   其他辅助函数:获取星期;获取公历日期之间天数;获取农历日期之间天数        
      int           GetWeekInfo(CALENDAR       m_gongli);               //根据公历日期计算星期        
      int           GetGongDays(CALENDAR       m_start,CALENDAR       m_end);//获取公历两个日期之间的天数        
      int           GetNongDays(CALENDAR       m_start,CALENDAR       m_end);//获取农历两个日期之间的天数        
      int           CompareTwoDate(CALENDAR       m_fir,CALENDAR       m_sec);//比较两个日期的大小        
      CALENDAR       GetCurGongDate();   //将当前公历日期合成为结构        
      CString       GetGanZhi(int       m_nongyear);   //获取农历年份的干支名称        
           
      ******************************************************        
      ***************                   调用规则结束                   ******************/        
           
           
           
           
           
      CCalendarConvert::CCalendarConvert()        
      {        
      m_minyear=1950;        
      m_maxyear=2050;        
           
      unsigned       char       data[100][3]=        
      {        
      {0x2f,0x6c,0xa0},{0x24,0xb5,0x50},{0xda,0x53,0x55},{0x2c,0x4d,0xa0},        
      {0x21,0xa5,0xb0},{0x57,0x45,0x73},{0xaa,0x52,0xb0},{0x1e,0xa9,0xa8},        
      {0x30,0xe9,0x50},{0x26,0x6a,0xa0},{0x9b,0xae,0xa6},{0x2d,0xab,0x50},        
      {0x23,0x4b,0x60},{0x18,0xaa,0xe4},{0xab,0xa5,0x70},{0x20,0x52,0x60},        
      {0x14,0xf2,0x63},{0x27,0xd9,0x50},{0x9d,0x5b,0x57},{0x2f,0x56,0xa0},        
           
      {0x24,0x96,0xd0},{0x1a,0x4d,0xd5},{0xad,0x4a,0xd0},{0x21,0xa4,0xd0},        
      {0x16,0xd4,0xd4},{0x29,0xd2,0x50},{0x9e,0xd5,0x58},{0x30,0xb5,0x40},        
      {0x25,0xb6,0xa0},{0x5b,0x95,0xa6},{0xae,0x95,0xb0},{0x23,0x49,0xb0},        
      {0x18,0xa9,0x74},{0x2b,0xa4,0xb0},{0xa0,0xb2,0x7a},{0x32,0x6a,0x50},        
      {0x27,0x6d,0x40},{0x1c,0xaf,0x46},{0xaf,0xab,0x60},{0x24,0x95,0x70},        
           
      {0x1a,0x4a,0xf5},{0x2d,0x49,0x70},{0xa2,0x64,0xb0},{0x16,0x74,0xa3},        
      {0x28,0xea,0x50},{0x1e,0x6b,0x58},{0xb1,0x5a,0xc0},{0x25,0xab,0x60},        
      {0x1b,0x96,0xd5},{0x2e,0x92,0xe0},{0xa3,0xc9,0x60},{0x17,0xd9,0x54},        
      {0x2a,0xd4,0xa0},{0x1f,0xda,0x50},{0x95,0x75,0x52},{0x27,0x56,0xa0},        
      {0x1c,0xab,0xb7},{0x30,0x25,0xd0},{0xa5,0x92,0xd0},{0x19,0xca,0xb5},        
           
      {0x2c,0xa9,0x50},{0x21,0xb4,0xa0},{0x96,0xba,0xa4},{0x28,0xad,0x50},        
      {0x1e,0x55,0xd9},{0x31,0x4b,0xa0},{0xa6,0xa5,0xb0},{0x5b,0x51,0x76},        
      {0x2e,0x52,0xb0},{0x23,0xa9,0x30},{0x98,0x79,0x54},{0x2a,0x6a,0xa0},        
      {0x1f,0xad,0x50},{0x15,0x5b,0x52},{0xa8,0x4b,0x60},{0x1c,0xa6,0xe6},        
      {0x2f,0xa4,0xe0},{0x24,0xd2,0x60},{0x99,0xea,0x65},{0x2b,0xd5,0x30},        
           
      {0x21,0x5a,0xa0},{0x16,0x76,0xa3},{0xa9,0x96,0xd0},{0x1e,0x4a,0xfb},        
      {0x31,0x4a,0xd0},{0x26,0xa4,0xd0},{0xdb,0xd0,0xb6},{0x2d,0xd2,0x50},        
      {0x22,0xd5,0x20},{0x17,0xdd,0x45},{0xaa,0xb5,0xa0},{0x1f,0x56,0xd0},        
      {0x15,0x55,0xb2},{0x28,0x49,0xb0},{0x9d,0xa5,0x77},{0x2f,0xa4,0xb0},        
      {0x24,0xaa,0x50},{0x59,0xb2,0x55},{0xac,0x6d,0x20},{0x20,0xad,0xa0}        
      };        
      CalendarData=new       char*[100];        
      for(int       i=0;i<100;i++)        
      {        
      CalendarData[i]=new       char[3];        
      for(int       j=0;j<3;j++)        
      CalendarData[i][j]=data[i][j];        
      }        
      }        
      CCalendarConvert::~CCalendarConvert()        
      {        
      for(int       i=0;i<100;i++)        
      delete[]       CalendarData[i];        
      delete[]       CalendarData;        
      }        
           
      //判断公历日期是否在界内        
      BOOL       CCalendarConvert::GongDataIsValid(CALENDAR       m_date)        
      {        
      if(m_date.year>1950       &&       m_date.year<2050)        
      return       TRUE;        
      else        
      {        
      if(m_date.year==1950)        
      {        
      if(m_date.month>2)        
      return       TRUE;        
      else        
      {        
      if(m_date.month==2)        
      {        
      if(m_date.day>16)        
      return       TRUE;        
      }        
      }        
      }        
      }        
      return       FALSE;        
      }        
           
      //判断农历日期是否在界内        
      BOOL       CCalendarConvert::NongDataIsValid(CALENDAR       m_date)        
      {        
      if(m_date.year>1949       &&       m_date.year<2049)        
      return       TRUE;        
      else        
      {        
      if(m_date.year==2049)        
      {        
      if(m_date.month<12)        
      return       TRUE;        
      else        
      {        
      if(m_date.month==12)        
      {        
      if(m_date.day<8)        
      return       TRUE;        
      }        
      }        
      }        
      }        
      return       FALSE;        
      }        
           
      //将农历日期转化为公历日期        
      CALENDAR       CCalendarConvert::ConvertToGongLi(CALENDAR       m_nongli)        
      {        
      int       days=DaysFromSpringDay(m_nongli);       //计算农历当前日期到春节的天数        
      days+=GetDaysFromStart(m_nongli.year);//加上春节到元旦的天数(以元旦为基准)        
      int       year=m_nongli.year;               //默认年份相同        
      int       alldays=GetGongYearDays(m_nongli.year);//计算农历年的公历天数        
      if(days>alldays)               //公历年份超前        
      {        
      days-=alldays;        
      year++;        
      }        
      CALENDAR       result=CalGongDate(year,days);//根据以元旦为基准的天数来确定日期        
      result.week=GetWeekInfo(result);        
      return       result;        
      }        
  Top

5 楼zh029t(蓝色海岸)回复于 2006-12-01 20:31:51 得分 0

错了Top

6 楼zh029t(蓝色海岸)回复于 2006-12-01 20:33:24 得分 0

上面是C#的,我去写个JAVA的Top

7 楼zhengjianqi(zzz)回复于 2006-12-01 21:03:56 得分 0

import   java.text.ParseException;  
  import   java.text.SimpleDateFormat;  
  import   java.util.Calendar;  
  import   java.util.Date;  
  import   java.util.*;  
   
  public   class   Lunar   {  
          private   int   year;  
          private   int   month;  
          private   int   day;  
          private   boolean   leap;  
          final   static   String   chineseNumber[]   =   {"一",   "二",   "三",   "四",   "五",   "六",   "七",   "八",   "九",   "十",   "十  
   
  一",   "十二"};  
          static   SimpleDateFormat   chineseDateFormat   =   new   SimpleDateFormat("yyyy年MM月dd日");  
          final   static   long[]   lunarInfo   =   new   long[]  
          {0x04bd8,   0x04ae0,   0x0a570,   0x054d5,   0x0d260,   0x0d950,   0x16554,   0x056a0,   0x09ad0,   0x055d2,  
            0x04ae0,   0x0a5b6,   0x0a4d0,   0x0d250,   0x1d255,   0x0b540,   0x0d6a0,   0x0ada2,   0x095b0,   0x14977,  
            0x04970,   0x0a4b0,   0x0b4b5,   0x06a50,   0x06d40,   0x1ab54,   0x02b60,   0x09570,   0x052f2,   0x04970,  
            0x06566,   0x0d4a0,   0x0ea50,   0x06e95,   0x05ad0,   0x02b60,   0x186e3,   0x092e0,   0x1c8d7,   0x0c950,  
            0x0d4a0,   0x1d8a6,   0x0b550,   0x056a0,   0x1a5b4,   0x025d0,   0x092d0,   0x0d2b2,   0x0a950,   0x0b557,  
            0x06ca0,   0x0b550,   0x15355,   0x04da0,   0x0a5d0,   0x14573,   0x052d0,   0x0a9a8,   0x0e950,   0x06aa0,  
            0x0aea6,   0x0ab50,   0x04b60,   0x0aae4,   0x0a570,   0x05260,   0x0f263,   0x0d950,   0x05b57,   0x056a0,  
            0x096d0,   0x04dd5,   0x04ad0,   0x0a4d0,   0x0d4d4,   0x0d250,   0x0d558,   0x0b540,   0x0b5a0,   0x195a6,  
            0x095b0,   0x049b0,   0x0a974,   0x0a4b0,   0x0b27a,   0x06a50,   0x06d40,   0x0af46,   0x0ab60,   0x09570,  
            0x04af5,   0x04970,   0x064b0,   0x074a3,   0x0ea50,   0x06b58,   0x055c0,   0x0ab60,   0x096d5,   0x092e0,  
            0x0c960,   0x0d954,   0x0d4a0,   0x0da50,   0x07552,   0x056a0,   0x0abb7,   0x025d0,   0x092d0,   0x0cab5,  
            0x0a950,   0x0b4a0,   0x0baa4,   0x0ad50,   0x055d9,   0x04ba0,   0x0a5b0,   0x15176,   0x052b0,   0x0a930,  
            0x07954,   0x06aa0,   0x0ad50,   0x05b52,   0x04b60,   0x0a6e6,   0x0a4e0,   0x0d260,   0x0ea65,   0x0d530,  
            0x05aa0,   0x076a3,   0x096d0,   0x04bd7,   0x04ad0,   0x0a4d0,   0x1d0b6,   0x0d250,   0x0d520,   0x0dd45,  
            0x0b5a0,   0x056d0,   0x055b2,   0x049b0,   0x0a577,   0x0a4b0,   0x0aa50,   0x1b255,   0x06d20,   0x0ada0};  
   
  //======   传回农历   y年的总天数  
          final   private   static   int   yearDays(int   y)   {  
                  int   i,   sum   =   348;  
                  for   (i   =   0x8000;   i   >   0x8;   i   >>=   1)   {  
                          if   ((lunarInfo[y   -   1900]   &   i)   !=   0)   sum   +=   1;  
                  }  
                  return   (sum   +   leapDays(y));  
          }  
   
  //======   传回农历   y年闰月的天数  
          final   private   static   int   leapDays(int   y)   {  
                  if   (leapMonth(y)   !=   0)   {  
                          if   ((lunarInfo[y   -   1900]   &   0x10000)   !=   0)  
                                  return   30;  
                          else  
                                  return   29;  
                  }   else  
                          return   0;  
          }  
   
  //======   传回农历   y年闰哪个月   1-12   ,   没闰传回   0  
          final   private   static   int   leapMonth(int   y)   {  
                  return   (int)   (lunarInfo[y   -   1900]   &   0xf);  
          }  
   
  //======   传回农历   y年m月的总天数  
          final   private   static   int   monthDays(int   y,   int   m)   {  
                  if   ((lunarInfo[y   -   1900]   &   (0x10000   >>   m))   ==   0)  
                          return   29;  
                  else  
                          return   30;  
          }  
   
  //======   传回农历   y年的生肖  
          final   public   String   animalsYear()   {  
                  final   String[]   Animals   =   new   String[]{"鼠",   "牛",   "虎",   "兔",   "龙",   "蛇",   "马",   "羊",   "猴",   "鸡",   "狗  
   
  ",   "猪"};  
                  return   Animals[(year   -   4)   %   12];  
          }  
   
  //======   传入   月日的offset   传回干支,   0=甲子  
          final   private   static   String   cyclicalm(int   num)   {  
                  final   String[]   Gan   =   new   String[]{"甲",   "乙",   "丙",   "丁",   "戊",   "己",   "庚",   "辛",   "壬",   "癸"};  
                  final   String[]   Zhi   =   new   String[]{"子",   "丑",   "寅",   "卯",   "辰",   "巳",   "午",   "未",   "申",   "酉",   "戌",   "  
   
  亥"};  
                  return   (Gan[num   %   10]   +   Zhi[num   %   12]);  
          }  
   
  //======   传入   offset   传回干支,   0=甲子  
          final   public   String   cyclical()   {  
                  int   num   =   year   -   1900   +   36;  
                  return   (cyclicalm(num));  
          }  
   
          /**  
            *   传出y年m月d日对应的农历.  
            *   yearCyl3:农历年与1864的相差数   ?  
            *   monCyl4:从1900年1月31日以来,闰月数  
            *   dayCyl5:与1900年1月31日相差的天数,再加40   ?  
            *  
            *   @param   cal  
            *   @return  
            */  
          public   Lunar(Calendar   cal)   {  
                  int   yearCyl,   monCyl,   dayCyl;  
                  int   leapMonth   =   0;  
                  Date   baseDate   =   null;  
                  try   {  
                          baseDate   =   chineseDateFormat.parse("1900年1月31日");  
                  }   catch   (ParseException   e)   {  
                          e.printStackTrace();   //To   change   body   of   catch   statement   use   Options   |   File   Templates.  
                  }  
   
  //求出和1900年1月31日相差的天数  
                  int   offset   =   (int)   ((cal.getTime().getTime()   -   baseDate.getTime())   /   86400000L);  
                  dayCyl   =   offset   +   40;  
                  monCyl   =   14;  
   
  //用offset减去每农历年的天数  
  //   计算当天是农历第几天  
  //i最终结果是农历的年份  
  //offset是当年的第几天  
                  int   iYear,   daysOfYear   =   0;  
                  for   (iYear   =   1900;   iYear   <   2050   &&   offset   >   0;   iYear++)   {  
                          daysOfYear   =   yearDays(iYear);  
                          offset   -=   daysOfYear;  
                          monCyl   +=   12;  
                  }  
                  if   (offset   <   0)   {  
                          offset   +=   daysOfYear;  
                          iYear--;  
                          monCyl   -=   12;  
                  }  
  //农历年份  
                  year   =   iYear;  
   
                  yearCyl   =   iYear   -   1864;  
                  leapMonth   =   leapMonth(iYear);   //闰哪个月,1-12  
                  leap   =   false;  
   
  //用当年的天数offset,逐个减去每月(农历)的天数,求出当天是本月的第几天  
                  int   iMonth,   daysOfMonth   =   0;  
                  for   (iMonth   =   1;   iMonth   <   13   &&   offset   >   0;   iMonth++)   {  
  //闰月  
                          if   (leapMonth   >   0   &&   iMonth   ==   (leapMonth   +   1)   &&   !leap)   {  
                                  --iMonth;  
                                  leap   =   true;  
                                  daysOfMonth   =   leapDays(year);  
                          }   else  
                                  daysOfMonth   =   monthDays(year,   iMonth);  
   
                          offset   -=   daysOfMonth;  
  //解除闰月  
                          if   (leap   &&   iMonth   ==   (leapMonth   +   1))   leap   =   false;  
                          if   (!leap)   monCyl++;  
                  }  
  //offset为0时,并且刚才计算的月份是闰月,要校正  
                  if   (offset   ==   0   &&   leapMonth   >   0   &&   iMonth   ==   leapMonth   +   1)   {  
                          if   (leap)   {  
                                  leap   =   false;  
                          }   else   {  
                                  leap   =   true;  
                                  --iMonth;  
                                  --monCyl;  
                          }  
                  }  
  //offset小于0时,也要校正  
                  if   (offset   <   0)   {  
                          offset   +=   daysOfMonth;  
                          --iMonth;  
                          --monCyl;  
                  }  
                  month   =   iMonth;  
                  day   =   offset   +   1;  
          }  
   
          public   static   String   getChinaDayString(int   day)   {  
                  String   chineseTen[]   =   {"初",   "十",   "廿",   "卅"};  
                  int   n   =   day   %   10   ==   0   ?   9   :   day   %   10   -   1;  
                  if   (day   >   30)  
                          return   "";  
                  if   (day   ==   10)  
                          return   "初十";  
                  else  
                          return   chineseTen[day   /   10]   +   chineseNumber[n];  
          }  
   
          public   String   toString()   {  
                  return   year   +   "年"   +   (leap   ?   "闰"   :   "")   +   chineseNumber[month   -   1]   +   "月"   +   getChinaDayString(day);  
          }  
          public   static   void   main(String[]   args){  
          Calendar   cal=Calendar.getInstance();  
          SimpleDateFormat   sdf=new   SimpleDateFormat("yyyy年MM月dd日");  
          cal.setTimeZone(TimeZone.getDefault());  
          System.out.println("公历日期:"+sdf.format(cal.getTime()));  
          Lunar   lunar=new   Lunar(cal);  
          System.out.print("农历日期:");  
          System.out.print(lunar.year+"年   ");  
          System.out.print(lunar.month+"月   ");  
          System.out.print(getChinaDayString(lunar.day));  
  }  
   
  }  
   
  这个可以运行,JDK1.5通过Top

8 楼zh029t(蓝色海岸)回复于 2006-12-01 21:04:20 得分 0

import   java.text.ParseException;  
  import   java.text.SimpleDateFormat;  
  import   java.util.Calendar;  
  import   java.util.Date;  
   
  public   class   test   {  
      private   int   year;  
      private   int   month;  
      private   int   day;  
      private   boolean   leap;  
      final   static   String   chineseNumber[]   =   {  
              "一",   "二",   "三",   "四",   "五",   "六",   "七",   "八",   "九",   "十",   "十一",   "十二"};  
      static   SimpleDateFormat   chineseDateFormat   =   new   SimpleDateFormat(  
              "yyyy年MM月dd日");  
      final   static   long[]   lunarInfo   =   new   long[]   {  
              0x04bd8,   0x04ae0,   0x0a570,   0x054d5,   0x0d260,   0x0d950,   0x16554,   0x056a0,  
              0x09ad0,   0x055d2,  
              0x04ae0,   0x0a5b6,   0x0a4d0,   0x0d250,   0x1d255,   0x0b540,   0x0d6a0,   0x0ada2,  
              0x095b0,   0x14977,  
              0x04970,   0x0a4b0,   0x0b4b5,   0x06a50,   0x06d40,   0x1ab54,   0x02b60,   0x09570,  
              0x052f2,   0x04970,  
              0x06566,   0x0d4a0,   0x0ea50,   0x06e95,   0x05ad0,   0x02b60,   0x186e3,   0x092e0,  
              0x1c8d7,   0x0c950,  
              0x0d4a0,   0x1d8a6,   0x0b550,   0x056a0,   0x1a5b4,   0x025d0,   0x092d0,   0x0d2b2,  
              0x0a950,   0x0b557,  
              0x06ca0,   0x0b550,   0x15355,   0x04da0,   0x0a5d0,   0x14573,   0x052d0,   0x0a9a8,  
              0x0e950,   0x06aa0,  
              0x0aea6,   0x0ab50,   0x04b60,   0x0aae4,   0x0a570,   0x05260,   0x0f263,   0x0d950,  
              0x05b57,   0x056a0,  
              0x096d0,   0x04dd5,   0x04ad0,   0x0a4d0,   0x0d4d4,   0x0d250,   0x0d558,   0x0b540,  
              0x0b5a0,   0x195a6,  
              0x095b0,   0x049b0,   0x0a974,   0x0a4b0,   0x0b27a,   0x06a50,   0x06d40,   0x0af46,  
              0x0ab60,   0x09570,  
              0x04af5,   0x04970,   0x064b0,   0x074a3,   0x0ea50,   0x06b58,   0x055c0,   0x0ab60,  
              0x096d5,   0x092e0,  
              0x0c960,   0x0d954,   0x0d4a0,   0x0da50,   0x07552,   0x056a0,   0x0abb7,   0x025d0,  
              0x092d0,   0x0cab5,  
              0x0a950,   0x0b4a0,   0x0baa4,   0x0ad50,   0x055d9,   0x04ba0,   0x0a5b0,   0x15176,  
              0x052b0,   0x0a930,  
              0x07954,   0x06aa0,   0x0ad50,   0x05b52,   0x04b60,   0x0a6e6,   0x0a4e0,   0x0d260,  
              0x0ea65,   0x0d530,  
              0x05aa0,   0x076a3,   0x096d0,   0x04bd7,   0x04ad0,   0x0a4d0,   0x1d0b6,   0x0d250,  
              0x0d520,   0x0dd45,  
              0x0b5a0,   0x056d0,   0x055b2,   0x049b0,   0x0a577,   0x0a4b0,   0x0aa50,   0x1b255,  
              0x06d20,   0x0ada0};  
   
      //======       传回农历       y年的总天数  
      final   private   static   int   yearDays(int   y)   {  
          int   i,   sum   =   348;  
          for   (i   =   0x8000;   i   >   0x8;   i   >>=   1)   {  
              if   (   (lunarInfo[y   -   1900]   &   i)   !=   0)  
                  sum   +=   1;  
          }  
          return   (sum   +   leapDays(y));  
      }  
   
      //======       传回农历       y年闰月的天数  
      final   private   static   int   leapDays(int   y)   {  
          if   (leapMonth(y)   !=   0)   {  
              if   (   (lunarInfo[y   -   1900]   &   0x10000)   !=   0)  
                  return   30;  
              else  
                  return   29;  
          }  
          else  
              return   0;  
      }  
   
      //======       传回农历       y年闰哪个月       1-12       ,       没闰传回       0  
      final   private   static   int   leapMonth(int   y)   {  
          return   (int)   (lunarInfo[y   -   1900]   &   0xf);  
      }  
   
      //======       传回农历       y年m月的总天数  
      final   private   static   int   monthDays(int   y,   int   m)   {  
          if   (   (lunarInfo[y   -   1900]   &   (0x10000   >>   m))   ==   0)  
              return   29;  
          else  
              return   30;  
      }  
   
      //======       传回农历       y年的生肖  
      final   public   String   animalsYear()   {  
          final   String[]   Animals   =   new   String[]   {  
                  "鼠",   "牛",   "虎",   "兔",   "龙",   "蛇",   "马",   "羊",   "猴",   "鸡",   "狗",   "猪"};  
          return   Animals[   (year   -   4)   %   12];  
      }  
   
      //======       传入       月日的offset       传回干支,       0=甲子  
      final   private   static   String   cyclicalm(int   num)   {  
          final   String[]   Gan   =   new   String[]   {  
                  "甲",   "乙",   "丙",   "丁",   "戊",   "己",   "庚",   "辛",   "壬",   "癸"};  
          final   String[]   Zhi   =   new   String[]   {  
                  "子",   "丑",   "寅",   "卯",   "辰",   "巳",   "午",   "未",   "申",   "酉",   "戌",   "亥"};  
          return   (Gan[num   %   10]   +   Zhi[num   %   12]);  
      }  
   
      //======       传入       offset       传回干支,       0=甲子  
      final   public   String   cyclical()   {  
          int   num   =   year   -   1900   +   36;  
          return   (cyclicalm(num));  
      }  
   
      /**  
        *       传出y年m月d日对应的农历.  
        *       yearCyl3:农历年与1864的相差数                                                           ?  
        *       monCyl4:从1900年1月31日以来,闰月数  
        *       dayCyl5:与1900年1月31日相差的天数,再加40                           ?  
        *       @param       cal  
        *       @return  
        */  
      public   test(Calendar   cal)   {  
          int   yearCyl,   monCyl,   dayCyl;  
          int   leapMonth   =   0;  
          Date   baseDate   =   null;  
          try   {  
              baseDate   =   chineseDateFormat.parse("1900年1月31日");  
          }  
          catch   (ParseException   e)   {  
              e.printStackTrace();   //To       change       body       of       catch       statement       use       Options       |       File       Templates.  
          }  
   
          //求出和1900年1月31日相差的天数  
          int   offset   =   (int)   (   (cal.getTime().getTime()   -   baseDate.getTime())   /  
                                                  86400000L);  
          dayCyl   =   offset   +   40;  
          monCyl   =   14;  
   
          //用offset减去每农历年的天数  
          //       计算当天是农历第几天  
          //i最终结果是农历的年份  
          //offset是当年的第几天  
          int   iYear,   daysOfYear   =   0;  
          for   (iYear   =   1900;   iYear   <   2050   &&   offset   >   0;   iYear++)   {  
              daysOfYear   =   yearDays(iYear);  
              offset   -=   daysOfYear;  
              monCyl   +=   12;  
          }  
          if   (offset   <   0)   {  
              offset   +=   daysOfYear;  
              iYear--;  
              monCyl   -=   12;  
          }  
          //农历年份  
          year   =   iYear;  
   
          yearCyl   =   iYear   -   1864;  
          leapMonth   =   leapMonth(iYear);   //闰哪个月,1-12  
          leap   =   false;  
   
          //用当年的天数offset,逐个减去每月(农历)的天数,求出当天是本月的第几天  
          int   iMonth,   daysOfMonth   =   0;  
          for   (iMonth   =   1;   iMonth   <   13   &&   offset   >   0;   iMonth++)   {  
              //闰月  
              if   (leapMonth   >   0   &&   iMonth   ==   (leapMonth   +   1)   &&   !leap)   {  
                  --iMonth;  
                  leap   =   true;  
                  daysOfMonth   =   leapDays(year);  
              }  
              else  
                  daysOfMonth   =   monthDays(year,   iMonth);  
   
              offset   -=   daysOfMonth;  
              //解除闰月  
              if   (leap   &&   iMonth   ==   (leapMonth   +   1))  
                  leap   =   false;  
              if   (!leap)  
                  monCyl++;  
          }  
          //offset为0时,并且刚才计算的月份是闰月,要校正  
          if   (offset   ==   0   &&   leapMonth   >   0   &&   iMonth   ==   leapMonth   +   1)   {  
              if   (leap)   {  
                  leap   =   false;  
              }  
              else   {  
                  leap   =   true;  
                  --iMonth;  
                  --monCyl;  
              }  
          }  
          //offset小于0时,也要校正  
          if   (offset   <   0)   {  
              offset   +=   daysOfMonth;  
              --iMonth;  
              --monCyl;  
          }  
          month   =   iMonth;  
          day   =   offset   +   1;  
      }  
   
      public   static   String   getChinaDayString(int   day)   {  
          String   chineseTen[]   =   {  
                  "初",   "十",   "廿",   "卅"};  
          int   n   =   day   %   10   ==   0   ?   9   :   day   %   10   -   1;  
          if   (day   >   30)  
              return   "";  
          if   (day   ==   10)  
              return   "初十";  
          else  
              return   chineseTen[day   /   10]   +   chineseNumber[n];  
      }  
   
      public   String   toString()   {  
          return   year   +   "年"   +   (leap   ?   "闰"   :   "")   +   chineseNumber[month   -   1]   +   "月"   +  
                  getChinaDayString(day);  
      }  
   
      public   static   void   main(String[]   args)   throws   ParseException   {  
          Calendar   today   =   Calendar.getInstance();  
          today.setTime(chineseDateFormat.parse("2006年12月1日"));  
          test   lunar   =   new   test(today);  
   
          System.out.println("北京时间:"   +   chineseDateFormat.format(today.getTime())   +  
                                                " 农历"   +   lunar);  
      }  
  }Top

9 楼zh029t(蓝色海岸)回复于 2006-12-01 21:05:19 得分 0

我晕发了才看见上面也发了Top

10 楼For_suzhen(不懂装懂)回复于 2006-12-01 21:58:33 得分 0

 
  上面是C#的,我去写个JAVA的  
   
       
  /////////////////////////////////////////////////////////  
  第一次听说C#文件的扩展名是CPP只记得是c++Top

11 楼ustcfrank(勇敢的心)回复于 2006-12-01 22:17:12 得分 0

http://www.java99.com/?m=Search&q=%D2%F5%C0%FATop

12 楼liufh44()回复于 2006-12-01 23:26:41 得分 0

这没什么,我们群里有人会编黄历  
  感兴趣就加:13546307Top

13 楼zhanshengkui()回复于 2006-12-02 13:36:19 得分 0

谢谢Top

相关问题

关键词

得分解答快速导航

  • 帖主:zhanshengkui

相关链接

  • CSDN Java频道
  • Java类图书
  • Java类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo