I am trying to convert a timestamp to milliseconds in a script using an external program. The external program outputs the time in the shortest possible format Example the external program can output any of the following formats:
"1:33.823" #1min:33 seconds.823 - shortest
"11:33.823" #11min:33 seconds.823 - short
"1:11:33.823" #1 hour 11min:33 seconds.823 - long
I need this value converted in milliseconds. so I tried [timestamp] $mystring
but it complains about the format in the first case. I thought about parsing the format manually with something like
$format='h\:mm\:ss\.ff'
[timespan]::ParseExact($mystring,$format , $null)
But the problem with this approach is that I have to predict every possible output format of the external program and implement all the cases manually (if shortest then $format=m\:ss\.fff else if short then $format=...
Or I can possibly split and define the string, loop from the back and define the attributes of the TimeSpan object manually.
My question is: are there any standard (good practice) conversion methods for my case provided in the language or are my "quick and dirty" solutions common?
Thanks