c#获取季度时间实例代码(季度的第一天)

时间:2021-05-20

复制代码 代码如下:
string firstDayOfThisQuarter = DateTime.Now.AddMonths(0-(DateTime.Now.Month - 1)%3).ToString("yyyy-MM-01");
Console.WriteLine("本季度的第一天为:{0}",firstDayOfThisQuarter);

string lastDayOfThisQuarter = DateTime.Parse(DateTime.Now.AddMonths(3 - ((DateTime.Now.Month - 1)%3)).ToString("yyyy-MM-01")).AddDays(-1).ToShortDateString();
string lastDayOfThisQuarter2 = DateTime.Parse(DateTime.Now.AddMonths(3 - ((DateTime.Now.Month - 1) % 3)).ToString("yyyy-MM-01")).AddDays(-1).ToString("yyyy-MM-dd");
Console.WriteLine("本季度的最后一天为:{0}", lastDayOfThisQuarter);
Console.WriteLine("本季度的最后一天为:{0}", lastDayOfThisQuarter2);

string firstDayOfNextQuarter = DateTime.Now.AddMonths(3 - ((DateTime.Now.Month - 1) % 3)).ToString("yyyy-MM-01");
string lastDayOfNextQuarter = DateTime.Parse(DateTime.Now.AddMonths(6 - ((DateTime.Now.Month - 1) % 3)).ToString("yyyy-MM-01")).AddDays(-1).ToShortDateString();
Console.WriteLine("下季度的第一天为:{0}", firstDayOfNextQuarter);
Console.WriteLine("下季度的最后一天为:{0}", lastDayOfNextQuarter);

string firstDayOfLastQuarter = DateTime.Now.AddMonths(-3 - ((DateTime.Now.Month - 1) % 3)).ToString("yyyy-MM-01");
string lastDayOfLastQuarter = DateTime.Parse(DateTime.Now.AddMonths(0 - ((DateTime.Now.Month - 1) % 3)).ToString("yyyy-MM-01")).AddDays(-1).ToShortDateString();
Console.WriteLine("上季度的第一天为:{0}", firstDayOfLastQuarter);
Console.WriteLine("上季度的最后一天为:{0}", lastDayOfLastQuarter);

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章