So I've got a string 00:00:15:185 which I need to tell is greater than 15 seconds.
Time format is HH:m:ss:FFF
This is clearly longer than 15 seconds but I can't compare it properly.
Current code is this:
value = "00:00:15:185";
if (DateTime.Parse(value) > DateTime.Parse("00:00:15:000"){
//do stuff
}
It's giving exceptions when I run it all the time and the program doesn't work when it should
Your string doesn't represent a time, but an amount of time. We have TimeSpan
for that.
var value = "00:00:15:185";
if (TimeSpan.ParseExact(value, @"hh\:mm\:ss\:FFF", CultureInfo.InvariantCulture)
> TimeSpan.FromSeconds(15))
{
//do stuff
}
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