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");
}
}
- C#實(shí)現(xiàn)帶陰歷顯示的日期代碼
- C# 日歷類功能的實(shí)例代碼
- C#簡(jiǎn)單輸出日歷的方法
- C#日歷樣式的下拉式計(jì)算器實(shí)例講解
- C#實(shí)現(xiàn)農(nóng)歷日歷的方法
- C# 常用日期時(shí)間函數(shù)(老用不熟)
- C#獲取上個(gè)月第一天和最后一天日期的方法
- C#由當(dāng)前日期計(jì)算相應(yīng)的周一和周日的實(shí)例代碼
- C#日期控件datetimepicker保存空值的三種方法
- c#的時(shí)間日期操作示例分享(c#獲取當(dāng)前日期)
- C#實(shí)現(xiàn)的陰歷陽(yáng)歷互相轉(zhuǎn)化類實(shí)例
相關(guān)文章
C#里SuperSocket庫(kù)不能發(fā)現(xiàn)命令的原因
這篇文章主要介紹C#里SuperSocket庫(kù)不能發(fā)現(xiàn)命令的原因,在使用SuperSocket來(lái)寫服務(wù)器的過程中,這是一個(gè)非??焖俚拈_發(fā)方式,也非常好用。不過學(xué)習(xí)的曲線有點(diǎn)高,在使用的過程中經(jīng)常會(huì)遇到各種各樣的問題。下面來(lái)看看學(xué)習(xí)舉例說明吧2021-10-10C#實(shí)現(xiàn)文件與Base64的相互轉(zhuǎn)換
本文主要介紹了C#實(shí)現(xiàn)文件與Base64的相互轉(zhuǎn)換,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-06-06C#實(shí)現(xiàn)簡(jiǎn)易計(jì)算器功能(2)(窗體應(yīng)用)
這篇文章主要為大家詳細(xì)介紹了C#實(shí)現(xiàn)簡(jiǎn)易計(jì)算器功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-01-01