欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C#判断某日为一个星期的第几天

程序员文章站 2022-09-26 21:04:14
直接上代码: int DayinWeek = 0; string week = DateTime.Today.DayOfWeek.ToString(); #region 获取DayinWeek值 switch (week) { case "Monday": DayinWeek = 1; break; ......

直接上代码:

 int dayinweek = 0;
            string week = datetime.today.dayofweek.tostring();
            #region 获取dayinweek值
            switch (week)
            {
                case "monday":
                    dayinweek = 1;
                    break;
                case "tuesday":
                    dayinweek = 2;
                    break;
                case "wednesday":
                    dayinweek = 3;
                    break;
                case "thursday":
                    dayinweek = 4;
                    break;
                case "friday":
                    dayinweek = 5;
                    break;
                case "saturday":
                    dayinweek = 6;
                    break;
                case "sunday":
                    dayinweek = 7;
                    break;
            }