#region 日期day自动加1
/// <summary>
/// 将当前日期加1天
/// </summary>
/// <param name="str">输入日期,如20120101</param>
/// <returns></returns>
public static string dateAdd1(string str)
{
//内容分解
int year = int.Parse(str.Substring(0, 4));
int month = int.Parse(str.Substring(4, 2));
int day = int.Parse(str.Substring(6));
if (month == 12)
{
if (day > 31)
{
MessageBox.Show("进行日期自加1时,输入的day大于31");
return "";
}
//若为最后一天,则年数加1
if (day == 31)
{
return (year + 1).ToString() + "0101";
}
else
day++;
}
else if(month ==1 || month ==3 || month ==5 ||month ==7 || month ==8 || month ==10)
{
if (day > 31)
{
MessageBox.Show("进行日期自加1时,输入的day大于31");
return "";
}
//月数为31天
if (day == 31)
{
if(month!=10)
return year.ToString() + "0"+(month + 1).ToString() + "01";
else
return year.ToString() + (month + 1).ToString() + "01";
}
else
{
day++;
}
}
else if(month ==2)
{
//2月份
int xianzhi = 28;
if (year % 4 == 0)
xianzhi = 29; //闰年2月份为29天
if (day > xianzhi)
{
MessageBox.Show("2月份进行日期自加1时,输入的day大于"+xianzhi.ToString());
return "";
}
if (day == xianzhi)
{
return year.ToString() + "0" + (month + 1).ToString() + "01";
}
else
day++;
}
else
{
//每月30天的情形
if (day > 30)
{
MessageBox.Show("进行日期自加1时,输入的day大于31");
return "";
}
if (day == 30)
{
if(month>8) //9+1为10,所以,9月份前也不用加0
return year.ToString() + (month + 1).ToString() + "01";
else
return year.ToString()+"0" + (month + 1).ToString() + "01";
}
else
day++;
}
string strd=day.ToString();
string strm=month.ToString();
if(day<10)
{
strd= "0"+strd;
}
if (month < 10)
{
strm = "0" + strm;
}
return year.ToString() + strm + strd;
}