1

我有这个:

string dataNow = DateTime.Today.tostring();
string dateAfter = dateNow + ( 20 days);

如何找到 20 天后的日期?
我如何找到一个月中的天数?

4

3 回答 3

7

您可能的意图是将日期用作日期类型DateTimeToString()在这种情况下,在完成日期操作之前不要打电话:

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

日期时间.AddDays


更新后:

获取当月的天数:

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

日期时间.DaysInMonth

于 2012-09-07T17:19:37.527 回答
0

这应该这样做:

    DateTime dtNow = DateTime.Today;
    string dateNow = dtNow.ToString();
    string dateAfter = dtNow.AddDays(20).ToString();
    int DaysInTheMonth = DateTime.DaysInMonth(dtNow.Year, dtNow.Month);
于 2012-09-07T17:22:37.300 回答
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);
于 2012-09-07T17:44:49.713 回答