zoukankan      html  css  js  c++  java
  • 根据时间段和周几查询包含的周几对应的日期

    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<DateTime> 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));
            }
    
    
        }
    }
    
  • 相关阅读:
    分分钟搞定Python之排序与列表
    分分钟搞定Python之排序与列表
    联系我
    联系我
    联系我
    联系表单 1_copy
    联系表单 1_copy
    联系表单 1_copy
    联系表单 1
    联系表单 1
  • 原文地址:https://www.cnblogs.com/wlwjc/p/3994015.html
Copyright © 2011-2022 走看看