格式要求:
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");
}
}
标签:c#,输出,本月月历
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
C#中dynamic关键字的正确用法(推荐)
2023-11-12 09:20:22
基于Java代码操作Redis过程详解
2022-03-28 06:53:58
![](https://img.aspxhome.com/file/2023/9/113259_0s.jpg)
通过实例解析Spring argNames属性
2023-09-14 10:43:13
![](https://img.aspxhome.com/file/2023/0/58540_0s.jpg)
Android Studio下载与安装简易教程
2022-05-28 10:25:30
![](https://img.aspxhome.com/file/2023/6/93276_0s.png)
Android分屏多窗口的实践代码
2021-06-21 21:34:58
Android快速实现发送邮件实例
2022-06-10 03:39:48
![](https://img.aspxhome.com/file/2023/7/137947_0s.png)
C#实现IDisposable接口释放非托管资源
2022-12-01 06:59:53
Java创建表格实例详解 <font color=red>原创</font>
2022-12-22 04:59:13
C语言实现扫雷游戏源代码
2021-10-17 14:20:44
浅谈android @id和@+id的区别
2021-10-28 06:06:09
Android开发Jetpack组件WorkManager用例详解
2023-05-09 03:27:07
Spring 自动装配的二义性实例解析
2021-12-16 00:37:55
![](https://img.aspxhome.com/file/2023/5/103865_0s.png)
MyBatis实现模糊查询的几种方式
2023-06-03 17:31:43
![](https://img.aspxhome.com/file/2023/9/92699_0s.png)
Java中的内部类你了解吗
2022-12-11 08:29:10
![](https://img.aspxhome.com/file/2023/0/62430_0s.png)
详解Android 获取手机中微信聊天记录方法
2021-10-25 02:32:38
![](https://img.aspxhome.com/file/2023/7/122087_0s.png)
Android实现图片拖动效果
2022-12-05 09:46:27
浅谈Android 指纹解锁技术
2023-06-04 18:59:06
![](https://img.aspxhome.com/file/2023/3/104663_0s.jpg)
SSH框架网上商城项目第24战之Struts2中处理多个Model请求的方法
2023-02-14 20:49:21
![](https://img.aspxhome.com/file/2023/0/125610_0s.jpg)
Java处理Webp图片格式转换的示例代码
2022-03-09 06:27:29
C# 获取程序集版本、文件版本
2022-12-14 13:47:31