I need to get total no of sec from string in time span format greater than 24 hrs. Below is code snipped i used
static void Main(string[] args)
{
string s = "24:55:00.00";
double d = (int)TimeSpan.Parse(s).TotalSeconds;
Console.WriteLine(d);
}
when i ran above getting Exception OverflowException was unhandled . when i use string less than 24hrs say like 23:55:05.09 . code is working fine. is it is real limitation of C# or i am missing something
Thanks
You can not use more than 23h in hours
OverflowException s represents a number that is less than TimeSpan.MinValue or greater than TimeSpan.MaxValue. -or- At least one of the days, hours, minutes, or seconds components is outside its valid range.
see here at MSDN
Max hours is 23, minutes 60 etc.
change your string to:
1:0:55:00.00
it will be equal to 24h55m
To be able to parse a string representation of a time span of 24 hours and 55 minutes you have to use this string:
1.0:55:00.00
If you are unsure about the string representation used by TimeSpan you can perform the reverse conversion:
(TimeSpan.FromDays(1) + TimeSpan.FromMinutes(55)).ToString()
This will return the string:
1.0:55:00
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With