The time span I want to parse is of the format dd-hh:mm:ss
It is the output by the Linux command that returns how long a process has been running.
Example:
string s = "5-15:10:20"; // 5 days 15h 10m 20s
TimeSpan.Parse(s);
This generates the error
System.FormatException was unhandled
Message="Input string was not in a correct format."
Source="mscorlib"
StackTrace:
at System.TimeSpan.StringParser.Parse(String s)
at System.TimeSpan.Parse(String s)
Important note: Code to be written in .net Framework 2.0
Is there a way to let the TimeParse correctly identify the first date part?
Edit: I tried replacing the - with : but it gives the same error.
The problem with your string is that the char "-" is a optional minus sign, which indicates a negative TimeSpan. So, you have to use the
Replace()method before parsing your string.On this link you can see all the common chars that works with that method. For that, something like that will work: