Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7600321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:52:56+00:00 2026-05-30T22:52:56+00:00

Am trying to convert my string value(the value is millisecond value) from seconds. Here

  • 0

Am trying to convert my string value(the value is millisecond value) from seconds.

Here is my code am trying to convert inside my xml append

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);

It’s throwing:

“The best Overloaded method match for System.Timespan.FromMilliseconds(double) has invalid arguments”

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

Thanks in Advance.

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

  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
            }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T22:52:58+00:00Added an answer on May 30, 2026 at 10:52 pm

    durationMilli is a string. To try to convert it to double use

    string durationMilli=DurationValue[1].TrimStart();
    double milliseconds;
    // Try to convert string to double
    if (double.TryParse(durationMilli, out milliseconds))
    {
       // milliseconds now contains your value
    
       TimeSpan ts = TimeSpan.FromSeconds(milliseconds);
       xmlElement.InnerText = DurationValue[1].TrimStart();
       newChild.AppendChild(xmlElement);
    }
    else
    {
       // durationMilli is not valid double - perhaps it contains letters or some special characters, report an error
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm extracting value from XML and trying to convert it to an appropriate Object...
I am trying to convert a string to unsigned long. Here is the code
I'm trying to convert a string date value from a submitted form into an
I am trying to convert a string value into a name of an attribute
I am trying to convert a string to a double. The code is very
I am trying to convert a string I read in from a file to
I'm trying to convert a string to a double value in .Net 3.5. Quite
I'm trying to convert this Javascript code: self.userSerialEvent = function (join, value, tokens) {
How to extract and save array from string parameter? I'm trying convert string beafore_create
I'm trying to convert characters in string into ascii value in Python Like ord('a[i]')

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.