⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 riqizhuanhuan.txt

📁 在网上载的一个日期转换代码,希望大家喜欢
💻 TXT
📖 第 1 页 / 共 3 页
字号:
  days+=GetNongRunYueDays(year);   
  return   days;   
  }   
    
  //获取农历年闰月天数   
  int     CCalendarConvert::GetNongRunYueDays(int   year)   
  {   
  if(GetNongRunYue(year)==0)   
  return   0;   
  int   days=RunYueIsLarge(year)?30:29;   
  return   days;   
  }   
    
  //获取农历闰月   
  int     CCalendarConvert::GetNongRunYue(int   year)   
  {   
  return   (CalendarData[year-m_minyear][2]   &   0x0f);   
  }   
    
  //公历日期到元旦的天数   
  int     CCalendarConvert::DaysFromNewYear(CALENDAR   m_day)   
  {   
  int   days=0;   
  for(int   i=1;i<m_day.month;i++)   
  days+=GetGongMonthDays(m_day.year,i);   
  days+=m_day.day;   
  return   days;   
  }   
    
  //农历日期到春节的天数   
  int     CCalendarConvert::DaysFromSpringDay(CALENDAR   m_day)   
  {   
  int   days=0;   
  int   month=GetNongRunYue(m_day.year);//处理闰月   
  if(month<m_day.month)   //闰月小于日期月份   
  days+=GetNongRunYueDays(m_day.year);   
  else   
  {   
  if((month==m_day.month)   &&   m_day.isrunyue)//日期月份是闰月   
  days+=GetNongRunYueDays(m_day.year);   
  }   
  for(int   i=1;i<m_day.month;i++)   
  days+=GetNongMonthDays(m_day.year,i);   
  days+=m_day.day;   
  return   days;   
  }   
    
  //公历年是否闰年   
  BOOL   CCalendarConvert::YearIsRunNian(int   year)   
  {   
  return   (CalendarData[year-m_minyear][0]   &   0x80);   
  }   
    
    
  //判断闰月是否为大月   
  BOOL   CCalendarConvert::RunYueIsLarge(int   year)   
  {   
  return   (CalendarData[year-m_minyear][0]&0x40);   
  }   
    
    
  //计算2的N次方   
  int     CCalendarConvert::Cal2N(int   n)   
  {   
  int   ret=1;   
  for(int   i=0;i<n;i++)   
  ret*=2;   
  return   ret;   
  }   
    
  //判断农历年的月份是否为大月   
  BOOL   CCalendarConvert::NongMonthIsLarge(int   year,int   month)   
  {   
  BOOL   ret=FALSE;   
  if(month<9)   
  {   
  if(CalendarData[year-m_minyear][1]   &   Cal2N(8-month))   
  ret=TRUE;   
  }   
  else   
  {   
  unsigned   char   ch=Cal2N(12-month);   
  ch<<=4;   
  if(CalendarData[year-m_minyear][2]   &   ch)   
  ret=TRUE;   
  }   
  return   ret;   
  }   
    
  //判断公历月份是否为大月(二月除外)   
  BOOL   CCalendarConvert::GongMonthIsLarge(int   month)   
  {   
  BOOL   ret=FALSE;   
  if(month<8)   
  {   
  if(month%2)   
  ret=TRUE;   
  }   
  else   
  {   
  if(!(month%2))   
  ret=TRUE;   
  }   
  return   ret;   
  }   
    
  //农历大年初一到元旦的天数   
  int     CCalendarConvert::GetDaysFromStart(int   year)   
  {   
  return   (CalendarData[year-m_minyear][0]&0x3f);   
  }   
    
    
  /*********暂时没有用到的成员函数***********/   
  //判断是否是闰月   
  BOOL   CCalendarConvert::MonthIsRunYue(int   year,int   month)   
  {   
  return   (month==GetNongRunYue(year));   
  }   
    
  //获取公历两个日期之间的天数   
  int     CCalendarConvert::GetGongDays(CALENDAR   m_start,CALENDAR   m_end)   
  {   
  int   days=0;   
  for(int   i=m_start.year;i<m_end.year;i++)   
  days+=GetGongYearDays(i);   
  days-=DaysFromNewYear(m_start);   
  days+=DaysFromNewYear(m_end);   
  return   days;   
  }   
    
  //获取农历两个日期之间的天数   
  int     CCalendarConvert::GetNongDays(CALENDAR   m_start,CALENDAR   m_end)   
  {   
  int   days=0;   
  for(int   i=m_start.year;i<m_end.year;i++)   
  days+=GetNongYearDays(i);   
  days-=DaysFromSpringDay(m_start);   
  days+=DaysFromSpringDay(m_end);   
  return   days;   
  }   
    
  //将当前公历日期合成为结构   
  CALENDAR   CCalendarConvert::GetCurGongDate()   
  {   
  CALENDAR   m_cal;   
  SYSTEMTIME   m_time;   
  GetLocalTime(&m_time);   
  m_cal.year=(int)m_time.wYear;   
  m_cal.month=(int)m_time.wMonth;   
  m_cal.day=(int)m_time.wDay;   
  m_cal.week=(int)m_time.wDayOfWeek;   
  return   m_cal;   
  }   
    
  //比较两个日期的大小   
  int     CCalendarConvert::CompareTwoDate(CALENDAR   m_fir,CALENDAR   m_sec)   
  {   
  int   m_state=0;   
    
  if(m_fir.year>m_sec.year)   
  m_state=1;   
  else   
  {   
  if(m_fir.year<m_sec.year)   
  m_state=-1;   
  else   
  {   
  if(m_fir.month>m_sec.month)   
  m_state=1;   
  else   
  {   
  if(m_fir.month<m_sec.month)   
  m_state=-1;   
  else   
  {   
  if(m_fir.day>m_sec.day)   
  m_state=1;   
  else   
  {   
  if(m_fir.day<m_sec.day)   
  m_state=-1;   
  else   
  m_state=0;   
  }   
  }   
  }   
  }   
  }   
    
  return   m_state;   
  }   
    
  //获取60年中的第N年的天干地支名称   
  CString   CCalendarConvert::GetNNameIn60(int   index)   
  {   
  char   ShengXiao[25]="鼠牛虎兔龙蛇马羊猴鸡狗猪";   
  char   TianGan[21]="甲乙丙丁戊己庚辛壬癸";   
  char   DiZhi[25]="子丑寅卯辰巳午未申酉戌亥";   
  char   buffer[20];   
  memset(buffer,0,20);   
  strcpy(buffer,"农历");   
    
  int   m_cur=0,m_this=0;   
  int   tian=0,di=0;   
  for(int   i=0;i<60;i++)   
  {   
  tian=i%10;   
  di=i%12;   
  if(m_this==index)   
  {   
  strncpy(&buffer[4],&TianGan[tian*2],2);   
  strncpy(&buffer[6],&DiZhi[di*2],2);   
  strcat(buffer,"年,");   
  strncpy(&buffer[12],&ShengXiao[di*2],2);   
  strcat(buffer,"年");   
  }   
  m_this++;   
  }   
  return   CString(buffer);   
  }   
    
    
  //获取农历年份的干支名称   
  CString   CCalendarConvert::GetGanZhi(int   m_nongyear)   
  {         
  int   m_index=(m_nongyear-1924)%60;   
  return   GetNNameIn60(m_index);   
  }   
    
  //将农历年的月份注入组合框   
  void   CCalendarConvert::NongMonthToList(int   m_n
Top

3 楼guanmj(雪在烧)回复于 2003-01-06 16:32:23 得分 40#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   },   
  {   26,   5,   1,   41,   0,   1,   0,   1,   0,   1,   0,   1,   1,   0,   1,   0,   1   },   /*   1952   */   
  {   44,   0,   3,   47,   0,   1,   0,   0,   1,   1,   0,   1,   1,   0,   1,   0,   1   },   
  {   33,   0,   4,   52,   1,   0,   1,   0,   0,   1,   0,   1,   1,   0,   1,   1,   0   },   
  {   23,   3,   5,   57,   0,   1,   0,   1,   0,   0,   1,   0,   1,   0,   1,   1,   1   },   
  {   42,   0,   6,   2,   0,   1,   0,   1,   0,   0,   1,   0,   1,   0,   1,   1,   1   },   /*   1956   */   
  {   30,   8,   1,   8,   1,   0,   1,   0,   1,   0,   0,   1,   0,   1,   0,   1,   0   },   
  {   48,   0,   2,   13,   1,   1,   1,   0,   1,   0,   0,   1,   0,   1,   0,   1,   0   },   
  {   38,   0,   3,   18,   0,   1,   1,   0,   1,   0,   1,   0,   1,   0,   1,   0,   1   },   
  {   27,   6,   4,   23,   1,   0,   1,   0,   1,   1,   0,   1,   0,   1,   0,   1,   0   },   /*   1960   */   
  {   45,   0,   6,   29,   1,   0,   1,   0,   1,   0,   1,   1,   0,   1,   0,   1,   0   },   
  {   35,   0,   0,   34,   0,   1,   0,   0,   1,   0,   1,   1,   0,   1,   1,   0,   1   },   
  {   24,   4,   1,   39,   1,   0,   1,   0,   0,   1,   0,   1,   0,   1,   1,   1,   0   },   
  {   43,   0,   2,   44,   1,   0,   1,   0,   0,   1,   0,   1,   0,   1,   1,   1,   0   },   /*   1964   */   
  {   32,   0,   4,   50,   0,   1,   0,   1,   0,   0,   1,   0,   0,   1,   1,   0,   1   },   
  {   20,   3,   5,   55,   1,   1,   1,   0,   1,   0,   0,   1,   0,   0,   1,   1,   0   },   
  {   39,   0,   6,   0,   1,   1,   0,   1,   1,   0,   0,   1,   0,   1,   0,   1,   0   },   
  {   29,   7,   0,   5,   0,   1,   0,   1,   1,   0,   1,   0,   1,   0,   1,   0,   1   },   /*   1968   */   
  {   47,   0,   2,   11,   0,   1,   0,   1,   0,   1,   1,   0,   1,   0,   1,   0,   1   },   
  {   36,   0,   3,   16,   1,   0,   0,   1,   0,   1,   1,   0,   1,   1,   0,   1,   0   },   
  {   26,   5,   4,   21,   0,   1,   0,   0,   1,   0,   1,   0,   1,   1,   1,   0,   1   },   
  {   45,   0,   5,   26,   0,   1,   0,   0,   1,   0,   1,   0,   1,   1,   0,   1,   1   },   /*   1972   */   
  {   33,   0,   0,   32,   1,   0,   1,   0,   0,   1,   0,   0,   1,   1,   0,   1,   1   },   
  {   22,   4,   1,   37,   1,   1,   0,   1,   0,   0,   1,   0,   0,   1,   1,   0,   1   },   
  {   41,   0,   2,   42,   1,   1,   0,   1,   0,   0,   1,   0,   0,   1,   0,   1,   1   },   
  {   30,   8,   3,   47,   1,   1,   0,   1,   0,   1,   0,   1,   0,   0,   1,   0,   1   },   /*   1976   */   
  {   48,   0,   5,   53,   1,   0,   1,   1,   0,   1,   0,   1,   0,   1,   0,   0,   1   },   
  {   37,   0,   6,   58,   1,   0,   1,   1,   0,   1,   1,   0,   1,   0,   1,   0,   1   },   
  {   27,   6,   0,   3,   1,   0,   0,   1,   0,   1,   1,   0,   1,   1,   0,   1,   0   },   
  {   46,   0,   1,   8,   1,   0,   0,   1,   0,   1,   0,   1,   1,   0,   1,   1,   0   },   /*   1980   */   
  {   35,   0,   3,   14,   0,   1,   0,   0,   1,   0,   0,   1,   1,   0,   1,   1,   1   },   
  {   24,   4,   4,   19,   1,   0,   1,   0,   0,   1,   0,   0,   1,   0,   1,   1,   1   },   
  {   43,   0,   5,   24,   1,   0,   1,   0,   0,   1,   0,   0,   1,   0,   1,   1,   1   },   
  {   32,   10,   6,   29,   1,   0,   1,   1,   0,   0,   1,   0,   0,   1,   0,   1,   1   },   /*   1984   */   
  {   50,   0,   1,   35,   0,   1,   1,   0,   1,   0,   1,   0,   0,   1,   0,   1,   0   },   
  {   39,   0,   2,   40,   0,   1,   1,   0,   1,   1,   0,   1,   0,   1,   0,   0,   1   },   
  {   28,   6,   3,   45,   1,   0,   1,   0,   1,   1,   0,   1,   1,   0,   1,   0,   0   },   

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -