Xml 在linq查询WP7中设置日期格式

Xml 在linq查询WP7中设置日期格式,xml,linq,windows-phone-7,Xml,Linq,Windows Phone 7,我有一个linq查询,如下所示 XDocument data = XDocument.Parse(xml); var persons = from query in data.Descendants("Table") select new MailList { Sender = (string)que

我有一个linq查询,如下所示

    XDocument data = XDocument.Parse(xml);

            var persons = from query in data.Descendants("Table")
                          select new MailList
                          {
                              Sender = (string)query.Element("FromUser"),
                              Body = (string)query.Element("Message"),

                              Date = (string)query.Element("mDate"),
                              Time = (string)query.Element("mTime"),

                          };
            EmailList.ItemsSource = persons;
我想将日期格式化为“MM/yy”,时间格式化为“hh:MM”
谢谢

您不能将直接强制转换与日期时间一起使用,因为它是一种值类型。使用普通类型转换,但如果日期格式不正确,请注意格式异常

var persons = from query in data.Descendants("Table")
          select new MailList
          {
              Sender = (string)query.Element("FromUser"),
              Body = (string)query.Element("Message"),
              Date = ((DateTime)query.Element("mDate")).ToString("MM/yy"),
              Time = ((DateTime)query.Element("mTime")).ToString("hh:mm"),

          };

您好,日期字段的类型是什么?