输出本月月历 c#实现输出本月的月历

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

输出本月月历 c#实现输出本月的月历

  2021-03-18 我要评论
想了解c#实现输出本月的月历的相关内容吗,在本文为您仔细讲解输出本月月历的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:c#,输出,本月月历,下面大家一起来学习吧。

格式要求:

复制代码 代码如下:

SU MO TU WE TH FR SA
         01 02 03 04
05 06 07 08 09 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30

代码:
复制代码 代码如下:

    class Interview1
    {
        static void Main()
        {
            PrintCalender(2011, 10);
        }
        public static void PrintCalender(int year, int month)
        {
            formatDate fd = new formatDate(year, month);
            string calender =
           @"SU MO TU WE TH FR Sa
            {0} {0} {0} {0} {0} {0} {0} {0}
            {0} {0} {0} {0} {0} {0} {0} {0}
            {0} {0} {0} {0} {0} {0} {0} {0}
            {0} {0} {0} {0} {0} {0} {0} {0}
            {0} {0} {0} {0} {0} {0} {0} {0}";

            calender = string.Format(calender, fd).TrimEnd();
            Console.WriteLine(calender);
        }
    }
    class formatDate : IFormattable
    {
        int num;
        int max;
        public formatDate(int year, int month)
        {
            DateTime dt = new DateTime(year, month, 1);
            num = (int)dt.DayOfWeek * -1;
            max = DateTime.DaysInMonth(year, month);
        }
        public string ToString(string format,IFormatProvider formatProvider)
        {
            return num++ < 0 || num > max ? "  " : num.ToString("00");
        }
    }

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们