zoukankan      html  css  js  c++  java
  • C# 获取当年的周六周日

     public void GetWMDay()
            {
                List<string> list = new List<string>();
                string year = "2019";
                DateTime counYear = Convert.ToDateTime(year + "-01-01"); //
                DateTime nestYear = counYear.AddYears(1);
    
                for (DateTime i = counYear; i < nestYear; i = i.AddDays(1))
                {
                    if ((int)i.DayOfWeek == 0)
                    {  // 周日    to do   }
    
                        list.Add("周日" + i.ToShortDateString());
                    }
                    else if ((int)i.DayOfWeek == 6)
                    {   //周六  to do  }       
                        list.Add("周六" + i.ToShortDateString());
                    }
                }
    
                MessageBox.Show("完成");
            }
      /// <summary>
            /// 获得指定年,月 的周六和周日的   年月日
            /// </summary>
            /// <param name="year"></param>
            /// <returns></returns>
            public List<DateTime> GetWMDay(int year,int month)
            {
                List<DateTime> list = new List<DateTime>();
                DateTime counYear = Convert.ToDateTime(string.Format("{0}-{1}-01",year,month)); 
                DateTime nestYear = counYear.AddMonths(1);
                for (DateTime i = counYear; i < nestYear; i = i.AddDays(1))
                {
                    if ((int)i.DayOfWeek == 0)
                    {  // 周日    to do   }
    
                        list.Add(i);
                    }
                    else if ((int)i.DayOfWeek == 6)
                    {   //周六  to do  }       
                        list.Add(i);
                    }
                }
                return list;
            }
  • 相关阅读:
    leetcode 283. 移动零
    leetcode 547. 朋友圈
    【剑指offer37】二叉树的序列化
    腾讯数据岗
    华为笔试题2
    华为笔试题1
    leetcode 分割回文串
    leetcode 正则表达式匹配
    leetcode241 为运算表达式设计优先级
    leetcode 44. 通配符匹配
  • 原文地址:https://www.cnblogs.com/enych/p/10210405.html
Copyright © 2011-2022 走看看