运行结果:
上代码:
代码语言:javascript复制using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
// string aa= "2021-05-24";
DateTime sj = new DateTime(2022,05,24);
int days = (int)sj.DayOfYear;
int week = (int)sj.DayOfWeek;
int month = (int)sj.Month;
int year = (int)sj.Year;
Console.Write("该日期是当年中的:" days "天n");
Console.Write("星期:" week "n");
int last = (int)DateTime.DaysInMonth(year, month);
// Console.Write(last);
//31天
Console.Write("星期日 星期一 星期二 星期三 星期四 星期五 星期六n");
for (int i = 1; i <= last; i )
{
if (i % 7 == 0)
{
Console.Write(" {0:00} n", i);
}
else {
Console.Write(" {0:00} ", i);
}
}
Console.ReadKey();
}
}
}