日历

 using System;
class classtoday
{
    private int  year;
    private int month;
    private static int day=1;
    classtoday()
    {
        DateTime today = DateTime.Now;
        this.year = today.Year;
        this.month = today.Month;
    }
    public static void Main()
    {
        classtoday show = new classtoday();
        show.display();
        show.view();
        Console.Read();
    }
    public string  returnmonth(int month)
    {
        string[] monthname ={ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" };
        return monthname [month-1];
    }
    public void view()
    {
        string choice;
        bool done = true;
        do
        {
            Console.WriteLine("日历菜单");
            Console.WriteLine("========================");
            Console.WriteLine("1,[>] 下月");
            Console.WriteLine("2,[<] 上月");
            Console.WriteLine("3,[〈〈] 去年");
            Console.WriteLine("4, [〉〉] 明年");
            Console.WriteLine("[*] 退出");
            Console.Write("输入你的选择:");
            choice = Console.ReadLine();
            switch (choice.ToLower())
            {
                case ">": if (month == 12)
                    { month = 1; year = year + 1; }
                    else month += 1;
                    break;
                case "<": if (month == 1)
                    { year -= 1; month = 12; }
                    else month -= 1;
                    break;
                case "<<": year -= 1; break;
                case ">>": year += 1; break;
                case "*": done = false; break;
                default:
                    Console.WriteLine("无效的选择");
                    break;
            }
            if (done)
                display();

        } while (true);
    }
    public void display()
    {
      
        int []arrday=new int [42];
        int dayindex;
        DateTime objdate=new DateTime(year,month,day);
        Console.WriteLine("{0}年-{1}月", year, returnmonth(month));
        int startdayindex = Convert.ToInt32(objdate.DayOfWeek);
        for (int i = 0; i < 31; i++)
        {
            if(i<DateTime.DaysInMonth(year,month))
            arrday[startdayindex + i] = i + 1;
           
        }
        Console.WriteLine(new String('*',64));
        Console.WriteLine("/t周日/t周一/t周二/t周三/t周四/t周五/t周六");
        Console.WriteLine(new String('*',64));
        for (int j = 0; j < 6; j++)
        {
            Console.Write("/t");
            for (int i = 0; i < 7; i++)
            {
                if (arrday[j * 7 + i] > 0)
                    Console.Write("{0,-2}/t", arrday[j * 7 + i]);
                else
                    Console.Write("{0,-2}/t", "");
            }
            Console.WriteLine();
        }
    }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值