源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

c#实现输出本月的月历

  • 时间:2020-12-07 12:34 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:c#实现输出本月的月历
格式要求:
[u]复制代码[/u] 代码如下:
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
代码:
[u]复制代码[/u] 代码如下:
    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");         }     }
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部