亲宝软件园·资讯

展开

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

人气:5
想了解c#获取季度时间实例代码(季度的第一天)的相关内容吗,在本文为您仔细讲解c#获取季度时间的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:季度时间,下面大家一起来学习吧。

复制代码 代码如下:

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);

加载全部内容

相关教程
猜你喜欢
用户评论