首页 > 代码库 > 获取当前日期是第几个星期

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

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;        }