Milliseconds to Seconds?
<p>Am trying to convert my string value(the value is millisecond value) from seconds.</p>

<p>Here is my code am trying to convert inside my xml append</p>

<pre><code>xmlElement = doc.CreateNode(XmlNodeType.Element, "duration", null);
//Convert Milliseconds to Seconds

string durationMilli=DurationValue[1].TrimStart();
TimeSpan ts = TimeSpan.FromSeconds(durationMilli);//tried this didn't work
TimeSpan ts = TimeSpan.FromMilliseconds(durationMilli).TotalSeconds;//then tried this didn't work either
xmlElement.InnerText = DurationValue[1].TrimStart();
newChild.AppendChild(xmlElement);
</code></pre>

<p>It's throwing:</p>

<blockquote>
  <p>"The best Overloaded method match for System.Timespan.FromMilliseconds(double) has invalid arguments"</p>
</blockquote>

<p>am not sure i have to convert the string to actual millisecond value then use timespan to convert to seconds ? please guide me.</p>

<p>Thanks in Advance.</p>

<p>Modified the code little bit and this what am using in my code (this is Answer)</p>

<pre><code>  string durationMilli = DurationValue[1].TrimStart();
            double milliseconds;
            // Try to convert string to double
            if (double.TryParse(durationMilli, out milliseconds))
            {
                // milliseconds now contains your value
                double ds = Math.Round(TimeSpan.FromMilliseconds(milliseconds).TotalSeconds);
                string totalsec = ds.ToString();
                xmlElement.InnerText = totalsec;
                newChild.AppendChild(xmlElement);
            }
            else
            {
                // durationMilli is not valid double - perhaps it contains letters or some special characters, report an error
            }
</code></pre>
