升級到VS 2010後,我得到這個FormatException。沒有什麼特別的。 代碼:VS 2010中升級後奇怪的FormatException
private void ManageDateEditControls()
{
apoDateEdit.DateTime = DateTime.Parse(string.Format("01/{0}/{1}", DateTime.Now.Month-1, DateTime.Now.Year));
eosDateEdit.DateTime = DateTime.Parse(string.Format("{0}/{1}/{2}", GetLastDayOfMonth(DateTime.Now.Month + 1),
DateTime.Now.Month - 1, DateTime.Now.Year)); <-- FormatException occurs in this line.
}
private static int GetLastDayOfMonth(int month)
{
// set return value to the last day of the month
// for any date passed in to the method
// create a datetime variable set to the passed in date
DateTime dtTo = new DateTime(DateTime.Now.Year, month, 1);
// overshoot the date by a month
dtTo = dtTo.AddMonths(1);
// remove all of the days in the next month
// to get bumped down to the last day of the
// previous month
dtTo = dtTo.AddDays(-(dtTo.Day));
// return the last day of the month
return dtTo.Day;
}
比方說,你現在得到,如果你運行31/6/2010。我認爲它是一個有效的日期。 我測試了生成的日期和它的好...這個項目在VS 2008中工作時從未遇到過這個問題。
任何想法?
我有點困惑 - 爲什麼31/6/2010是有效日期? – 2010-07-12 00:15:23