C#查看上个月的最后一天的日期

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text; 
namespace ConsoleApplication71

{
    class Program
    {
        static void Main(string[] args)
        {            
            Console.WriteLine("Today: {0}", DateTime.Now);
            var today = DateTime.Now;
            var month = new DateTime(today.Year, today.Month, 1);          
            var last = month.AddDays(-1);

            Console.WriteLine(" End Date of Last Month : {0}", last.ToString("yyy/MM/dd"));

        }
    }
}
在C#中如何获取上个月的最后一天

DateTime Now属性

这显示了系统的当前日期和时间,表示为当地时间。
换句话说,现在属性返回具有现在的日期和时间值的DateTime对象。

DateTime Month属性

此属性用于获取日期的月份组件。

日期:2020-04-11 22:50:32 来源:oir作者:oir