我有这个:
string dataNow = DateTime.Today.tostring();
string dateAfter = dateNow + ( 20 days);
如何找到 20 天后的日期?
我如何找到一个月中的天数?
您可能的意图是将日期用作日期类型DateTime
。ToString()
在这种情况下,在完成日期操作之前不要打电话:
string dataNow = DateTime.Today.AddDays(20).ToString();
更新后:
获取当月的天数:
var date = DateTime.Today;
int days = DateTime.DaysInMonth(date.Year, date.Month);
这应该这样做:
DateTime dtNow = DateTime.Today;
string dateNow = dtNow.ToString();
string dateAfter = dtNow.AddDays(20).ToString();
int DaysInTheMonth = DateTime.DaysInMonth(dtNow.Year, dtNow.Month);
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);