在VC++ 中 怎么样得到 某年某月的天数 是多少天呢?? 例如2008年11月份 是30天2006年2月是28 求现成的函数!!!  谢谢? 其他方法也可以

解决方案 »

  1.   

    switch(month)
    {
    case 1:
      return 31;
    case 2:
      if (闰年)
        return 29;
      else
        return 28;
    case 3:
     // ...
    case 12:
      return 31;
    }
      

  2.   

    COleDateTime d1(2006,11,1,0,0,0);
    COleDateTime d2(2006,12,1,0,0,0);
    COleDateTimeSpan ds = d2-d1;
    cout<<ds.GetDays();
      

  3.   

    int month_day1[12]={31,28,31,30,31,30,31,31,30,31,30,31};//非闰年
    int month_day2[12]={31,29,31,30,31,30,31,31,30,31,30,31};//闰年
    然后把月份作为下标在这两个数组里一查就行。
      

  4.   

    whiteclouds的方法不错. 简单实用.
      

  5.   

    switch(nMonth)
    {
    case 1:
    case 3:
    case 5:
    case 7:
    case 8:
    case 10:
    case 12:
    nLastDay = 31;
    break;
    case 4:
    case 6:
    case 9:
    case 11:
    nLastDay = 30;
    break;
    case 2:
    if(nYear % 4 == 0)
    if(nYear % 100 == 0)
    if(nYear % 400 == 0)
    nLastDay = 29;
    else
    nLastDay = 28;
    else
    nLastDay = 29;
    else
    nLastDay = 28;
    }
      

  6.   

    int GetDays(int year, int month)
    {
      int nRet;
      switch(month)
      {
        case 4:
        case 6:
        case 9:
        case 11:
          nRet = 30;
          break;
        case 2:
          if((year%4 == 0 && year%100 != 0) || year%400 == 0)
            nRet = 29;
          else
            nRet = 28;
          break;
        default:
          nRet = 31;
      }
      return nRet;
    }
      

  7.   

    这么简单的问题,程序用得着写那么长,还搞数组?if (2 == Month)
      Days = !(Time.wYear % 4) && (Time.wYear % 100) || !(Time.wYear % 400) ? 29 : 28;
    else if (Month < 8)
      Days = 30 + (Month & 1);
    else
      Days = 31 - (Month & 1);到这里后Days即为所要的天数.
      

  8.   

    上面的Time.wYear是年的意思,我从我的一个工程中拷贝过来的,没有修改,上面的程序把它改成Year就好理解了.