@echo off setlocal rem get timestamp at start of task call :GetTimestamp ts1 echo start timestamp = %ts1% rem do time consuming task... this sample task takes about 4 seconds. for /l %%A in (0,1,200000) do rem. rem get timestamp at end of task call :GetTimestamp ts2 echo end timestamp = %ts2% rem get difference between two timestamps call :CalcTimestampDelta td %ts2% %ts1% echo timestamp delta = %td% rem display duration call :DurationStr d %td% echo duration = %d% goto :eof :GetTimestamp {ResultVarName} for /f %%A in ('mshta "javascript:(new ActiveXObject('scripting.filesystemobject')).getstandardstream(1).writeline((new Date()).getTime());close()"') do set %1=%%A goto :eof :CalcTimestampDelta {ResultVarName} {Timestamp1} {Timestamp2} for /f %%A in ('mshta "javascript:(new ActiveXObject('scripting.filesystemobject')).getstandardstream(1).writeline(Math.abs(%3-%2));close()"') do set %1=%%A goto :eof :DurationStr {ResultVarName} {TimestampDelta} for /f "delims=" %%A in ('mshta "javascript:t=new Date(%2);r=(t.getUTCSeconds()+t.getUTCMilliseconds()/1000)+' seconds';h=t.getUTCDate()*24+t.getUTCHours();r=((m=t.getUTCMinutes())||h?m+' minutes'+(r?' ':''):'')+r;r=(h?h+' hours'+(r?' ':''):'')+r;(new ActiveXObject('scripting.filesystemobject')).getstandardstream(1).writeline(r);close()"') do set %1=%%A goto :eof