Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print time in a batch file (milliseconds)

How do I print the time (in ms) in a Windows batch file?

I want to measure the time that passes between lines in my batch file, but Windows's "time /T" does not print milliseconds.

like image 414
Assaf Lavie Avatar asked Mar 03 '09 08:03

Assaf Lavie


2 Answers

%time% should work, provided enough time has elapsed between calls:

@echo OFF  @echo %time% ping -n 1 -w 1 127.0.0.1 1>nul @echo %time% 

On my system I get the following output:

6:46:13.50
6:46:13.60

like image 141
Patrick Cuff Avatar answered Sep 22 '22 01:09

Patrick Cuff


If you're doing something like

for /l %%i in (1,1,500) do @echo %time% 

or

if foo (     echo %time%     do_something     echo %time% ) 

then you could simply put a setlocal enabledelayedexpansion at the beginning of your batch file and use !time! instead of %time% which gets evaluated on execution, not on parsing the line (which includes complete blocks enclosed in parentheses).

like image 44
Joey Avatar answered Sep 21 '22 01:09

Joey