2010年1月31日 星期日

C# 抓取每月天數

        int Month = 1;
Label1.Text = "";

if (TextBox1.Text != "")
{
for (int i = 0; i < 12; i++)
{
int daymun = DateTime.DaysInMonth(int.Parse(TextBox1.Text), Month);
Label1.Text += "" + TextBox1.Text + "年" + Month.ToString() + "月,共" + daymun.ToString() + "天<BR>";
Month = Month + 1;
}
}
結果
2010年1月,共31天
2010年2月,共28天
2010年3月,共31天
2010年4月,共30天
2010年5月,共31天
2010年6月,共30天
2010年7月,共31天
2010年8月,共31天
2010年9月,共30天
2010年10月,共31天
2010年11月,共30天
2010年12月,共31天

沒有留言:

張貼留言