【问题标题】:C# DateTime The last 1 days of each month [closed]C# DateTime 每个月的最后 1 天 [关闭]
【发布时间】:2023-03-22 08:54:01
【问题描述】:

昨天。在这里,我们从当天减去一天。我们通过在当天添加 -1 来做到这一点。这是必要的,因为没有提供“减去天数”方法。 笔记: 该示例是几年前运行的。输出自然会根据您运行它的日期而有所不同。 和: DateTime.Today 始终设置为机器的本地时间,具体取决于当前系统。

【问题讨论】:

标签: c# datetime


【解决方案1】:
public DateTime GetLastDayOfMonth(int year, int month)
{
    month += 1;
    if (month>12)
    {
        month = 1;
    }
    return new DateTime(year, month, 1).AddDays(-1);
}

【讨论】:

    猜你喜欢
    • 2023-04-10
    • 1970-01-01
    • 1970-01-01
    • 2012-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-21
    • 1970-01-01
    相关资源
    最近更新 更多