博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
根据时间段和周几查询包含的周几对应的日期
阅读量:5763 次
发布时间:2019-06-18

本文共 915 字,大约阅读时间需要 3 分钟。

using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace weekDemo{    class Program    {        static void Main(string[] args)        {            DayOfWeek[] dw = new DayOfWeek[] { DayOfWeek.Monday, DayOfWeek .Sunday};            var query = GetWeekDays(DateTime.Now, DateTime.Now.AddMonths(1), dw);            foreach (var item in query.ToList())            {                Console.WriteLine(item.ToShortDateString() + "--星期:" + System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(item.DayOfWeek));            }                   }        public static IEnumerable
GetWeekDays(DateTime begin, DateTime end,DayOfWeek[] dws) { return Enumerable.Range(0, (end - begin).Days).Where(c => dws.Contains(begin.AddDays(c).DayOfWeek)).Select(c => begin.AddDays(c)); } }}

 

转载于:https://www.cnblogs.com/wlwjc/p/3994015.html

你可能感兴趣的文章