What is the windows analog to unix time command?


This is a duplicate of an older question on stackoverflow - see there for many answers :)


You can use timeit.exe from the Windows Server 2003 Resource Kit.


timeit [-f FileName] [-a] [-c] [-i] [-d] [-s] [-t] [-k KeyName | -r KeyName] 
[-m Mask] [Command]

-f FileName  
Specifies the name of the database file where TimeIt keeps a history of 
previous timings. The default file name is .\Timeit.dat

-k KeyName
Specifies the keyname to use for this timing run.

-r KeyName
Specifies the key name to remove from the database. If the key name is 
followed by a comma and a number, the slowest time (positive number) or
the fastest time (negative number) for that key name will be removed.

Specifies that TimeIt should display average of all timings for the 
specified key name.

Ignores nonzero return codes from the program run by TimeIt.

Shows detail for average.

Suppresses systemwide counters.

Specifies tabular output.

Forces a re-sort of the database.

-m Mask
Specifies the processor affinity mask.

Specifies the command to time.
  • But the unix 'time' command doesn't return the current epoch time, so that's not relevant. 'time' runs the command you put on the commandline after it, then tells you how much real/user/system time the command took. unixhelp.ed.ac.uk/CGI/man-cgi?time has more details. – James Polley Dec 28 '09 at 6:01
  • Ah. I read the question incorrectly. – John T Dec 28 '09 at 6:15
  • ** Sigh ** seems my answer was mentioned on the SO page you linked to. – John T Dec 28 '09 at 6:22
  • :) Easy to be confused, especially when time on DOS/Windows is equivalent to date on *nix – James Polley Dec 28 '09 at 6:24
  • Oh I'm very familiar with both. I just thought of the windows clock when it said Windows analog, as analog is a type of clock. The other meaning of analog wasn't on my mind :P – John T Dec 28 '09 at 6:33

Through my own research online, I was not able to find a way to do this via a batch file directly. However, I was able to find this solution that worked for me:

In toEpoch.vbs:

WScript.Echo DateDiff("s", "01/01/1970 00:00:00", Now())

Then called from my batch script like so:

for /f "delims=" %%x in ('cscript /nologo filename.vbs') do set epoch=%%x

That set the %epoch% variable with the current unix timestamp and I was able to use it as I needed to.

Hope this helps.


Write a C program using the GetProcessTimes function, you could find its documentation in: http://msdn.microsoft.com/en-us/library/ms683223%28VS.85%29.aspx.

In the examples of the book "Windows System Programming" comes a program that use that function to retrieve exactly what you need(Elapsed, Kernel, User times). The program is call "timep.exe" and it can be found in the runX subdirectories (the X comes from the version of Visual Studio used in the compilation) inside the zipped examples archive. Here is the author page from where you could download that archive http://www.jmhartsoftware.com/, of course the source code is also there so you could see exactly how timep.exe works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy