如何用C#控制台程序来做显示日历的程序,急求

lxseven7 2008-06-09 02:51:37
请教如何能用C#来做显示日历的程序啊,比如提示用户输入个“9”月,然后,控制台中就显示当前9月的全部日期,并在开头对应相应的星期表(如windows自带的那个日历程序)
...全文
235 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
yagebu1983 2008-06-17
  • 打赏
  • 举报
回复
mark!!
lxseven7 2008-06-09
  • 打赏
  • 举报
回复
额 给错分了
绝代坏坏 2008-06-09
  • 打赏
  • 举报
回复
呵呵楼上正解
gomoku 2008-06-09
  • 打赏
  • 举报
回复

using System;

class Program
{
static void Main()
{
ShowCalendar(2);
}

static void ShowCalendar(int month)
{
Console.WriteLine("Su Mo Tu We Th Fr Sa");
Console.WriteLine("--------------------------------");

int year = DateTime.Now.Year;
int days = DateTime.DaysInMonth(year, month);

for (int day = 1; day <= days; day++)
{
string str = "";
for(DateTime d = new DateTime(year, month, day); d.DayOfWeek != DayOfWeek.Saturday;)
{
str += string.Format("{0,-5}", day);
if( ++day > days ) break;
d = new DateTime(year, month, day);
}
if (day < days)
{
str += string.Format("{0,-5}", day);
str = str.PadLeft(35);
}
Console.WriteLine(str);
}
}
}

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧