日期:2014-05-17 浏览次数:20761 次
public static void SplitDate(DateTime begin, DateTime end)
{
if (begin > end)
{
SplitDate(end, begin);
return;
}
int beginYear = begin.Year;
int endYear = end.Year;
for (; beginYear <= endYear; beginYear++)
{
Console.WriteLine((beginYear > begin.Year ? new DateTime(beginYear, 1, 1).ToShortDateString() : begin.AddYears(beginYear - begin.Year).ToShortDateString()) + "--" + (beginYear == endYear ? end.ToShortDateString() : new DateTime(begin.Year, 12, 31).ToShortDateString()));
}
}
DateTime start = Convert.ToDateTime("2011-06-25");
DateTime end = Convert.ToDateTime("2014-01-13");
for (; start <= end; start = new DateTime(start.AddYears(1).Year, 1, 1))
{
DateTime gaptime = new DateTime(start.AddYears(1).Year, 1, 1);
if (gaptime.AddDays(-1) >= end)
{
Console.WriteLine("开始时间:" + start + "\t" + "结束时间:" + end);
}
&nb