获取当前日期是第几个星期

public int weekofyear(DateTime dtime)
        {
            int weeknum = 0;
            DateTime firstDay = new DateTime(dtime.Year, 1, 1);
            int weekday = Convert.ToInt32(firstDay.DayOfWeek) - 1;
            if (weekday == 0)
            {
                weekday = 7;
            }
            int daynum = dtime.DayOfYear - (7 - weekday);
            if (daynum < 0)
            {
                return 1;
            }
            if (daynum % 7 == 0)
            {
                weeknum = daynum / 7 + 1;
            }
            else
            {
                weeknum = daynum / 7 + 2;
            }
            return weeknum;
        }
posted @ 2014-07-23 09:43  wxing67  阅读(156)  评论(0编辑  收藏  举报