C# 用c语言获取当月的所有周数#

C# 用c语言获取当月的所有周数#,c#,.net,C#,.net,我想用c#like获得本月的所有周数 您能否在此帮助我以上述格式获取当月的所有日期以及周日名称,此代码就足够了: using System; public class Program { public static void Main(string[] args) { int year = 2020; int month = 3; DateTime startDate = new DateTime(year, month, 1);

我想用c#like获得本月的所有周数


您能否在此帮助我

以上述格式获取当月的所有日期以及周日名称,此代码就足够了:

using System; 

public class Program 
{ 
 public static void Main(string[] args)
  {
       int year = 2020;
       int month = 3;
       DateTime startDate = new DateTime(year, month, 1);
       DateTime endDate = startDate.AddMonths(1);
      while (startDate.DayOfWeek != DayOfWeek.Sunday)
       startDate = startDate.AddDays(1);
      for (DateTime result = startDate; result < endDate; result = result.AddDays(1))
       Console.WriteLine(result.ToString(" dd.MM.yyyy dddd"));
       Console.ReadLine(); 
  } 
}
using System; 

public class Program 
{ 
 public static void Main(string[] args)
  {
      int year = 2020;
      int month = 3;
      DateTime startDate = new DateTime(year, month, 1);
      DateTime endDate = startDate.AddMonths(1);
    while (startDate.DayOfWeek != DayOfWeek.Monday)
      startDate = startDate.AddDays(1);
    for (DateTime result = startDate; result < endDate; result = result.AddDays(7))
      Console.WriteLine(result.ToString(" dd.MM.yyyy dddd"));
      Console.ReadLine();

   } 
}
使用系统;
公共课程
{ 
公共静态void Main(字符串[]args)
{
国际年=2020年;
整月=3;
DateTime startDate=新日期时间(年、月、1);
DateTime endDate=startDate.AddMonths(1);
while(startDate.DayOfWeek!=DayOfWeek.Sunday)
startDate=startDate.AddDays(1);
对于(DateTime result=startDate;result

要以上述格式仅获取每周/当月所有周的特定日期和日期(如周一),此代码就足够了:

using System; 

public class Program 
{ 
 public static void Main(string[] args)
  {
       int year = 2020;
       int month = 3;
       DateTime startDate = new DateTime(year, month, 1);
       DateTime endDate = startDate.AddMonths(1);
      while (startDate.DayOfWeek != DayOfWeek.Sunday)
       startDate = startDate.AddDays(1);
      for (DateTime result = startDate; result < endDate; result = result.AddDays(1))
       Console.WriteLine(result.ToString(" dd.MM.yyyy dddd"));
       Console.ReadLine(); 
  } 
}
using System; 

public class Program 
{ 
 public static void Main(string[] args)
  {
      int year = 2020;
      int month = 3;
      DateTime startDate = new DateTime(year, month, 1);
      DateTime endDate = startDate.AddMonths(1);
    while (startDate.DayOfWeek != DayOfWeek.Monday)
      startDate = startDate.AddDays(1);
    for (DateTime result = startDate; result < endDate; result = result.AddDays(7))
      Console.WriteLine(result.ToString(" dd.MM.yyyy dddd"));
      Console.ReadLine();

   } 
}
使用系统;
公共课程
{ 
公共静态void Main(字符串[]args)
{
国际年=2020年;
整月=3;
DateTime startDate=新日期时间(年、月、1);
DateTime endDate=startDate.AddMonths(1);
while(startDate.DayOfWeek!=DayOfWeek.Monday)
startDate=startDate.AddDays(1);
对于(DateTime result=startDate;result

您的意思是想获得每个日期的工作日名称吗?这就是您的示例所展示的。您自己尝试了什么?仔细彻底地研究它及其成员。
DateTime.DaysInMonth(year,month)
获取月份的天数
date.ToString(“d.M.yyyy ddddd”,CultureInfo.InvariantCulture)
以所需格式表示
日期