我有label1 label2和button1我按了button1,label1文本會根據上個月的總天數(可以說'31'天)和基於最後一年的總天數改變說「365」天)去年的總天數
我只知道如何上個月總天數,我用DateTime.DaysInMonth編碼,但有一個爲DateTime.DaysInYear沒有一種方法是不是
這裏是我的代碼
private void button1_Click(object sender, EventArgs e)
{
//Last Month
string month = DateTime.Now.ToString("MM");
int months = Int32.Parse(month);
int previousmonths = months - 1;
//Month in this Year
string year = DateTime.Now.ToString("yyyy");
int years = Int32.Parse(year);
int daysmonth = DateTime.DaysInMonth(years, previousmonths);
MessageBox.Show(daysmonth.ToString());
//Last Year
string year = DateTime.Now.ToString("yyyy");
int years = Int32.Parse(year);
int lastyears = years - 1;
int daysyear = DateTime.DaysInYear(lastyears);
MessageBox.Show(daysyear.ToString());
}
假設你已經查過它是如何完成的,你的代碼看起來很奇怪 - https://www.bing.com/search?q = c%23 + days + in + year ... –