c#获取季度时间实例代码(季度的第一天)
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);