Converting a stopwatch time to milliseconds (regex)
- by Nick
I'm trying to figure out the best way to convert a string containing a time to an integer number of milliseconds. I'm using a suboptimal way using a bunch of preg_match()'s and some array handling, but I was wondering if there was an elegant way.
Here are some example stopwatch times (some wouldn't actually be seen on a stopwatch but need to be converted anyway):
3:34:05.81
34:05
5 (just 5 seconds)
89 (89 seconds)
76:05 (76 minutes, 5 seconds)
Millseconds will not extend past 2 decimal places. You can give me an example using either PHP or Javascript regex functions.
Thanks!