任意输入一个日期输出是当年的第几天星期几
class Program { static void Main(string[] args) { string putDateStr = Console.ReadLine(); DateTime putDate = new DateTime(Int32.Parse(putDateStr.Split(' ')[0]), Int32.Parse(putDateStr.Split(' ')[1]), Int32.Parse(putDateStr.Split(' ')[2])); DateTime offsetDate = putDate; DateTime initDate = new DateTime(putDate.Year, 01, 01); int dayOffset = 0; int weekOffset = (int)putDate.DayOfWeek; while (offsetDate >= initDate) { dayOffset++; if (dayOffset > 1) { weekOffset--; if (weekOffset == -1) { weekOffset = 6; } } offsetDate = offsetDate.AddDays(-1); } Console.WriteLine($"该日期是当年的第{dayOffset}天星期{(int)putDate.DayOfWeek},当年的第一天是星期{weekOffset}"); Console.ReadKey(); } }