我使用这些代码来转换当前日期时间并减去用户在文本框中键入的日期时间。但它在转换时出现错误。如何将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