C# 获取本季季初, 本季度第一天
using System;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("本季度第一天:{0}", GetQuarterFirstDate(DateTime.Now));
Console.Read();
}
/// <summary>
/// 获取本季季初, 本季度第一天
/// </summary>
/// <param name="dateTime">当前时间 DateTime.Now or DateTime.UtcNow</param>
/// <returns>后面的具体时、分、秒和传入值相等</returns>
public static DateTime GetQuarterFirstDate(DateTime dateTime)
{
// 本季季初
return dateTime.AddMonths(0 - ((dateTime.Month - 1) % 3)).AddDays(1 - dateTime.Day);
}
}
}