我通过解析XElement从xml中检索日期和时间字符串。日期和时间值分别通过
在检索到日期值后,我将其解析为DateTime变量。
然后将此“dt”值设置为XAML UI上的日期选择器值。
我将连接日期值和字符串 'b' 和 'c'。
任何帮助都将不胜感激...
file.Element("Date").Value
和file.Element("Time").Value
检索。在检索到日期值后,我将其解析为DateTime变量。
DateTime dt,ts;
dt = file.Element("Date").Value; // the value is say 12/29/2012
然后将此“dt”值设置为XAML UI上的日期选择器值。
datepicker.Value = dt;
我还有一个时间选择器,其值必须由从xml中检索到的时间值设置。为了设置时间选择器的值,我执行以下操作。声明3个字符串,例如:
string a = file.Element("Time").Value; // the value is say 9:55 AM
string b = file.Element("Time").Value.Substring(0, 5) + ":00"; // eg 9:55:00
string c = file.Element("Time").Value.Substring(5); // the value is ' AM'
我将连接日期值和字符串 'b' 和 'c'。
string total = file.Element("Date").Value + " " + b + c;
total
的值现在是'2012年12月29日上午9:55:00'
然后我尝试将这个total
字符串解析为DateTime,但它抛出了一个格式异常
DateTime.Parse(total, CultureInfo.InvariantCulture);
任何帮助都将不胜感激...
DateTime.Parse(total, CultureInfo.InvariantCulture);
而不是帖子中的DateTime.Parse("total, CultureInfo.InvariantCulture");
,对吗? - mlorbetske