我使用這些代碼來轉換當前日期時間並減去用戶在文本框中鍵入的日期時間。但它在轉換時出現錯誤。如何將Persian Calendar日期字符串轉換爲DateTime?
PersianCalendar p = new System.Globalization.PersianCalendar();
DateTime date = new DateTime();
date = DateTime.Parse(DateTime.Now.ToShortDateString());
int year = p.GetYear(date);
int month = p.GetMonth(date);
int day = p.GetDayOfMonth(date);
string str = string.Format("{0}/{1}/{2}", year, month, day);
DateTime d1 = DateTime.Parse(str);
DateTime d2 = DateTime.Parse(textBox9.Text);
string s = (d2 - d1).ToString().Replace(".00:00:00", "");
textBox10.Text = (d2 - d1).ToString().Replace(".00:00:00","");
而從字符串轉換日期時間至今的時間這條線將給予一個錯誤:DateTime d1 = DateTime.Parse(str);
請幫我解決這個問題。
在此先感謝
什麼是你的錯誤? – Tejs
爲什麼要格式化DateTime.Now然後再解析它?爲什麼你給'date'賦值,然後立即給它賦一個不同的值?你爲什麼要將波斯年/月/日解析爲不在波斯日曆中?它*非常*不清楚你想要做什麼,以及波斯日曆適合什麼地方。 –
你不會對'字符串s'做任何事情。 – comecme