Note that there are some explanatory texts on larger screens.

plurals
  1. POConvert string to DateTime with Convert.ToDateTime
    primarykey
    data
    text
    <p>I'm a but frustrated. I'm playing around with xml-files. So this is my automatically created xml-File:</p> <pre><code>&lt;Files&gt; &lt;Lists&gt; &lt;oList&gt; &lt;Object&gt; &lt;Name&gt;test1&lt;/Name&gt; &lt;DateCreated&gt;2/11/2013 4:35:05 PM&lt;/DateCreated&gt; &lt;DateDeadline&gt;2/17/2013 12:00:00 AM&lt;/DateDeadline&gt; &lt;Reward&gt;none&lt;/Reward&gt; &lt;Description&gt;chocolate amedei 9&lt;/Description&gt; &lt;/Object&gt; &lt;/oList&gt; &lt;/Lists&gt; &lt;/Files&gt; </code></pre> <p>The many start elements in the beginning have to be there because I want to extend the file later. So now I want to read this xml-file and create an object of a class (ThingsToDoObjects, it's supposed to become a to-do-list some day) that needs exactly the parameters stored in the xml-file. This Object should be stored in a list. So this is what I have so far:</p> <pre><code>XmlDocument xmlListDoc = new XmlDocument(); xmlListDoc.Load(xmlFilePath); foreach (XmlNode xnode in xmlListDoc.SelectNodes("Files/Lists/oList/Object")) { string n = xnode.SelectSingleNode("Name").InnerText.ToString(); DateTime c = Convert.ToDateTime(xnode.SelectSingleNode("DateCreated").InnerText.ToString()); DateTime d = Convert.ToDateTime(xnode.SelectSingleNode("DateDeadline").InnerText.ToString()); string r = xnode.SelectSingleNode("Reward").InnerText.ToString(); string de = xnode.SelectSingleNode("Description").InnerText.ToString(); ThingsToDoObjects NeuObject = new ThingsToDoObjects(n, c, d, r, de); o.Add(NeuObject); } </code></pre> <p>Now when I debug the following happens: n is created fine, c is created fine. But d just doesn't work.It gives an error: </p> <blockquote> <p>"The string was not recognized as a valid DateTime"</p> </blockquote> <p>(That's my translation from German, so maybe the error might be called a bit different. What's going on there? I hope I just made some stupid mistake.</p> <p>By the way: I tried the <code>ParseExactly()</code> method but it dind't work either and gave the same error.</p> <p>Thanks in advance to everone who answers.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload