C#获取时间属于第几周

int getWeek(DateTime dt)
    {
        DateTime time = Convert.ToDateTime(dt.ToString("yyyy") + "-01-01");
        TimeSpan ts = dt - time;
        int iii = (int)time.DayOfWeek;
        int day = int.Parse(ts.TotalDays.ToString("F0"));
        if (iii == 0)
        {
            day--;
        }
        else
        {
            day = day - (7 - iii) - 1;
        }
        int week = ((day + 7) / 7) + 1;
        return week;
    }

posted @ 2017-01-09 16:44  huangzebin  阅读(3966)  评论(0编辑  收藏  举报