首页 > 代码库 > 获取日期星期几

获取日期星期几

/// <summary>
        /// 获取日期星期几
        /// </summary>
        /// <param name="addDate"></param>
        /// <returns></returns>
        private string GetWeek(DateTime addDate)
        {
            int y = addDate.Year; int m = addDate.Month; int d = addDate.Day;

            if (m == 1) m = 13;
            if (m == 2) m = 14;
            int week = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7 + 1;
            string weekstr = "";
            switch (week)
            {
                case 1: weekstr = "星期一"; break;
                case 2: weekstr = "星期二"; break;
                case 3: weekstr = "星期三"; break;
                case 4: weekstr = "星期四"; break;
                case 5: weekstr = "星期五"; break;
                case 6: weekstr = "星期六"; break;
                case 7: weekstr = "星期日"; break;
            }

            return weekstr;



获取日期星期几