I have a string like this: "00:02:37.6940000". Is there an easy way to convert/parse that into seconds? Do I have to regex it into pieces and do it that way?
I don't care about the milliseconds.
Parse is the default method of the [TimeSpan] type, so:
([timespan]"00:02:37.6940000").TotalSeconds
should work, too.
With error trapping:
$input_ts = "00:02:37.6940000"
if ($input_ts -as [TimeSpan])
{$time = ([TimeSpan]$input_ts).TotalSeconds}
else {Write-Warning "Input value $input_ts not valid for timespan"}
[TimeSpan]::TryParse().