要做一个考勤管理系统。
头大了!!!生成的文件里面天数和月份还有日期都要对应!!求算法!public string[] DateTimeAndDay(DateTime 传入的年月日)
{//根据月份算这个月的天数。
  return[]//这个月的天数 
}带该有个思路也 可以~~要考虑什么???
多数无意~ 上思路才是王道!!!

解决方案 »

  1.   

    System.DateTime.DaysInMonth(1999, 2);
      

  2.   

    DateTime.DaysInMonth 方法】
    返回指定年和月中的天数。参数
    year
    年份。 month
    月份(介于 1 到 12 之间的一个数字)。 返回值
    指定 year 中 month 的天数。 例如,如果 month 等于 2(表示二月),则返回值为 28 或 29,具体取决于 year 是否为闰年。 
      

  3.   

    手写的话
    public int GetDays(int year, int month)
            {
                int[] days = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
                if (month == 2 && ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0))
                {
                    return 29;
                }
                else
                {
                    return days[month];
                }
            }
      

  4.   

    什么意思 一个月的天数指扣除周末+节假日吗 扣除周末应该不难吧 
    判断日期的dayofweek就知道 节假日搞一张维护表 关联一下判断扣除即可
      

  5.   

    根据月份算这个月的天数。
        DateTime d = new DateTime(2008,8,8);
        System.Globalization.Calendar c = new System.Globalization.GregorianCalendar();
        int daysInAugust = c.GetDaysInMonth(d.Year, d.Month);  // 31
    法定节假日
    that is a bit difficult, you might:
        DateTime[] m_Holidays = new DateTime[]
        {
            new DateTime(2008,  1,  1),
            new DateTime(2008,  5,  1),
            new DateTime(2008, 12, 25),
            //...
        };
        bool IsHoliday(DateTime d)
        {
            return Array.IndexOf<DateTime>(m_Holidays, d) >= 0;        // or, 
            foreach (DateTime h in m_Holidays)
            {
                if (h.Month == d.Month && h.Day == d.Day) return true;
            }
            return false;
        }
      

  6.   


            string[] dtstr = new string[] { "1-1", "5-1", "4-4", "6-8", "10-1" };        public int  DateTimeAndDay(DateTime dt)
            {
                //根据月份算这个月的天数。            int t = DateTime.DaysInMonth(dt.Year, dt.Month);
                int j = t;
                for (int i = 1; i < j+1; i++)
                {
                    DateTime ddt = new DateTime(dt.Year, dt.Month, i);
                    if (ddt.DayOfWeek == DayOfWeek.Saturday || ddt.DayOfWeek == DayOfWeek.Sunday)
                        t = t - 1;
                    foreach (string s in dtstr)
                    {
                       DateTime  dddt = Convert.ToDateTime(dt.Year.ToString() + "-" + s);
                        if (ddt.Equals(dddt))
                            t = t - 1;                }
                }            return t; 
            }