private static void Main()
{
var cur = System.DateTime.Now;
for (var i = 0; i < 12; i++)
{
pp(cur.AddMonths(i), 0);
Console.WriteLine("*********************************************************");
}
}
private static void pp(DateTime now, int offset)
{
var current = now.AddMonths(offset);
var curMoth = current.Month;
var curYear = current.Year;
var calendarbegin = new DateTime(curYear, curMoth, 1);
var calendarend = calendarbegin.AddMonths(1).AddDays(-1);
var listd = new List<int>();
int week1 = (int)calendarbegin.DayOfWeek;//获取当年当月1号的星期
if (week1 > 0)
{
calendarbegin = calendarbegin.AddDays(-week1);
}
int week30 = (int)calendarend.DayOfWeek;
if (week30 < 6)
{
calendarend = calendarend.AddDays(6 - week30);
}
var days = (calendarend - calendarbegin).Days + 1;
Console.WriteLine(now.ToString() + "=>" + days);
Console.WriteLine("日\t一\t二\t三\t四\t五\t六\t");
for (int i = 0; i < days; i++)
{
if (i % 7 == 0)
Console.WriteLine();
var output = calendarbegin.AddDays(i);
string format = "{0}";
if (output.Month != curMoth)
{
format = "({0})";
}
Console.Write(string.Format(format, calendarbegin.AddDays(i).Day) + "\t");
}
Console.WriteLine();
}