The easy way would be if the milliseconds field is always two digits:
Translates to trim off the first 0 characters, then keep up to (size of string - 3) characters. Which would lop off the
.07 in your example. In fact, this should always work: I just realised you're using the built in %time% variable (teaches me to read), which should always return with a two digit 'ms' value.
If your milliseconds could be a different number of digits (e.g.
0.1 instead of
0.10), some kind of string search command would be needed. And here it is:
Ok, this seems hackish.. but it's Windows command line, so hey. This will trim off the dot and everything after it, so it will work no matter how many digits of precision your ms value is (e.g.
0.1 instead of
EndLocal && set _time=%_time%
Make sure there is only one dot in your time when this is used.
Attempting to explain now. Of course, you can just use it and save yourself the headache of trying to understand.
- SetLocal defines a local scope. Anything changed between now and the EndLocal will not last past the EndLocal. You cannot have a SetLocal within a SetLocal.
- EnableDelayedExpansion allows the use of !s, among other things. It lets me use a variable within a variable.
- I add an _EndOfStringMarker so if the ms value (in your example
07) occurs anywhere else, e.g. the seconds value, that will not be replaced.
- I trim off from before the dot, including the dot, leaving me with everything after the dot. The command line doesn't let me do it the other way around.
- I replace everything after the dot in the original string with nothing, leaving me with the time ending in a dot.
- I replace the dot with nothing.
- I end the local area, to tidy things up a bit. To keep the new time value outside this local scope, I have to set it to itself on the same line. It's yet another quirk of the command line.
Source for the dodgy trim to end: http://ss64.com/nt/syntax-replace.html