c#根據年月獲取所有日期集合

        //根據年月獲取所有日期

         //txt="2019-04"
        public List<string> CalTime(string txt) {
           DateTime beginTime=DateTime.Parse(txt+"-01");//本月初
           DateTime endTime=DateTime.Parse( beginTime.AddMonths(1).AddDays(-1).ToShortDateString());//本月最後一天
            List<string> dateList = new List<string>();
            for (DateTime dt = beginTime; dt <= endTime; dt = dt.AddDays(1))
            {
                dateList .Add(dt.ToShortDateString());
            }
            return dateList ;
        }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章