欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2024-02-23 13:20:10
复制代码 代码如下:string firstdayofthisquarter = datetime.now.addmonths(0-(datetime.now.month...

复制代码 代码如下:

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