我正在使用Visual Studio,並且我想將我在文本框中的字符串轉換爲DateTime
格式。我正在使用函數Convert.ToDateTime()
,但返回的值是最小值(0/0/0001 00:00:00
)。將字符串轉換爲日期時間返回最小值
什麼問題?
從我的文本框中檢索字符串的代碼。
//pass startdate end date to studentResult.aspx
Session["startdate"] = txtStartDate.Text.ToString();
Session["enddate"] = txtEndDate.Text.ToString();
將字符串轉換爲日期時間格式的代碼。
string startdate = (string)(Session["startdate"]);
string enddate = (string)(Session["enddate"]);
DateTime one = Convert.ToDateTime(startdate);
DateTime two = Convert.ToDateTime(enddate);
你是什麼'textbox'值的值,它會返回false? –
你不能分享代碼嗎? – Kangkan
您是否嘗試將文本框本身轉換爲DateTime或其文本屬性?即'Convert.ToDateTime(myTextBox)'或'Convert.ToDateTime(myTextBox.Text)' – Squid