Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>@echo off rem Get start time: for /F "tokens=1-4 delims=:.," %%a in ("%time%") do ( set /A "start=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100" ) rem Any process here... rem Get end time: for /F "tokens=1-4 delims=:.," %%a in ("%time%") do ( set /A "end=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100" ) rem Get elapsed time: set /A elapsed=end-start rem Show elapsed time: set /A hh=elapsed/(60*60*100), rest=elapsed%%(60*60*100), mm=rest/(60*100), rest%%=60*100, ss=rest/100, cc=rest%%100 if %mm% lss 10 set mm=0%mm% if %ss% lss 10 set ss=0%ss% if %cc% lss 10 set cc=0%cc% echo %hh%:%mm%:%ss%,%cc% </code></pre> <hr> <p><strong>EDIT 2017-05-09:</strong> <em>Shorter method added</em></p> <p>I developed a shorter method to get the same result, so I couldn't resist to post it here. The two <code>for</code> commands used to separate time parts and the three <code>if</code> commands used to insert leading zeros in the result are replaced by two long arithmetic expressions, that could even be combined into a single longer line.</p> <p>The method consists in directly convert a variable with a time in "HH:MM:SS.CC" format into the formula needed to convert the time to centiseconds, accordingly to the mapping scheme given below:</p> <pre><code> HH : MM : SS . CC (((10 HH %%100)*60+1 MM %%100)*60+1 SS %%100)*100+1 CC %%100 </code></pre> <p>That is, insert <code>(((10</code> at beginning, replace the colons by <code>%%100)*60+1</code>, replace the point by <code>%%100)*100+1</code> and insert <code>%%100</code> at end; finally, evaluate the resulting string as an arithmetic expression. In the time variable there are two different substrings that needs to be replaced, so the conversion must be completed in two lines. To get an elapsed time, use <code>(endTime)-(startTime)</code> expression and replace both time strings in the same line.</p> <p><strong>EDIT 2017/06/14:</strong> <em>Locale independent adjustment added</em></p> <pre><code>@echo off setlocal EnableDelayedExpansion set "startTime=%time: =0%" set /P "=Any process here..." set "endTime=%time: =0%" rem Get elapsed time: set "end=!endTime:%time:~8,1%=%%100)*100+1!" &amp; set "start=!startTime:%time:~8,1%=%%100)*100+1!" set /A "elap=((((10!end:%time:~2,1%=%%100)*60+1!%%100)-((((10!start:%time:~2,1%=%%100)*60+1!%%100)" rem Convert elapsed time to HH:MM:SS:CC format: set /A "cc=elap%%100+100,elap/=100,ss=elap%%60+100,elap/=60,mm=elap%%60+100,hh=elap/60+100" echo Start: %startTime% echo End: %endTime% echo Elapsed: %hh:~1%%time:~2,1%%mm:~1%%time:~2,1%%ss:~1%%time:~8,1%%cc:~1% </code></pre> <p>You may review a detailed explanation of this method at <a href="https://stackoverflow.com/questions/42603119/arithmetic-operations-with-hhmmss-times-in-batch-file/42603985#42603985">this answer</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload