2012-09-07 66 views

回答

7

您的可能意圖是使用日期作爲日期類型DateTime。在這種情況下,不叫ToString()你完成操作的日期前:

string dataNow = DateTime.Today.AddDays(20).ToString(); 

DateTime.AddDays


更新後:

要獲得當月的天數:

var date = DateTime.Today; 
int days = DateTime.DaysInMonth(date.Year, date.Month); 

DateTime.DaysInMonth

+0

非常感謝!!!!!!!!!!!!!!!! – CyberDx

+1

@Cyber​​Dx:請注意,您應該考慮在解決問題時接受答案。 –

0

這應做到:

DateTime dtNow = DateTime.Today; 
    string dateNow = dtNow.ToString(); 
    string dateAfter = dtNow.AddDays(20).ToString(); 
    int DaysInTheMonth = DateTime.DaysInMonth(dtNow.Year, dtNow.Month); 
0
DateTime today = DateTime.Today; 
DateTime later = today.AddDays(20); 

string todayAsString = today.ToString("d"); 
string laterAsString = later.ToString("d"); 

int daysThisMonth = DateTime.DaysInMonth(today.Year, today.Month); 
int daysLaterMonth = DateTime.DaysInMonth(later.Year, later.Month);