c#實(shí)現(xiàn)輸出本月的月歷
格式要求:
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");
}
}
相關(guān)文章
macOS系統(tǒng)下Vscode的python配置教程
這篇文章主要介紹了macOS系統(tǒng)下Vscode的python配置教程,本文通過圖文并茂的形式給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-04-04
C#進(jìn)階系列 WebApi身份認(rèn)證解決方案推薦:Basic基礎(chǔ)認(rèn)證
下面小編就為大家?guī)硪黄狢#進(jìn)階系列 WebApi身份認(rèn)證解決方案推薦:Basic基礎(chǔ)認(rèn)證。小編覺得挺不錯的,現(xiàn)在分享給大家。給大家一個參考。一起跟隨小編過來看看吧2016-03-03
DevExpress中GridControl列轉(zhuǎn)義的實(shí)現(xiàn)方法
這篇文章主要介紹了DevExpress中GridControl列轉(zhuǎn)義的實(shí)現(xiàn)方法,在項(xiàng)目開發(fā)中有一定的實(shí)用價值,需要的朋友可以參考下2014-08-08
WinForm特效之桌面上的遮罩層實(shí)現(xiàn)方法
這篇文章主要介紹了WinForm特效之桌面上的遮罩層實(shí)現(xiàn)方法,是一個非常實(shí)用的技巧,需要的朋友可以參考下2014-09-09

