這是我第一篇文章。該應用程序是我已經設置了培養應用爲EN-GB一個winform但同時檢查並保存我將其轉換回爲en-US我得到這個錯誤字符串未被recornized爲有效的DateTime字符串未被識別爲有效日期時間
CultureInfo currentCulture = new CultureInfo("en-US");
string strCheckDate = CheckConvertCulture(input);
string date = DateTime.Now.ToString("M/d/yyyy");
if (DateTime.ParseExact(strCheckDate,currentCulture.ToString(),null)> DateTime.ParseExact(date,currentCulture.ToString(),null))
{
return false;
}
else
{
return true;
}
我在做什麼錯在這裏
這是我converCurrentCulture代碼
string strdate = string.Empty;
CultureInfo currentCulture = CultureInfo.CurrentCulture;
System.Globalization.DateTimeFormatInfo usDtfi = new System.Globalization.CultureInfo("en-US", false).DateTimeFormat;
if (currentCulture.ToString() != "en-US")
{
strdate = Convert.ToDateTime(Culturedate).ToString(usDtfi.ShortDatePattern);
}
else
{
strdate = Culturedate;
}
return strdate;
這是我做過什麼來得到它的工作,但如果用戶選擇像29/02/2013無效的日期將它的工作不確定,
CultureInfo currentCulture = new CultureInfo("en-GB");
string date = DateTime.Now.ToString("dd/MM/yyyy", currentCulture);
由於應用程序默認爲EN-GB
if (DateTime.Parse(input) > DateTime.Parse(date))
{
return false;
}
else
{
return true;
}
沒有提供'CheckConvertCulture'的定義,你不會得到一個好的答案。 – spender 2013-03-15 11:33:56
什麼是'strCheckDate'和'CheckConvertCulture'? – 2013-03-15 11:35:03
strCheckDate只是從下拉日期,需要找出如何編輯我的代碼,並把CheckConvertCulture :) – Adrian 2013-03-15 11:39:03