在C#中如何获取当前月的第一天日期

DateTime Now 属性

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

DateTime Month 属性

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

在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 StartDate = new DateTime(today.Year, today.Month, 1);
Console.WriteLine("Start Date of current Month : {0}", StartDate.ToString("yyy/MM/dd"));

}

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