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. -a Specifies that TimeIt should display average of all timings for the specified key name. -i Ignores nonzero return codes from the program run by TimeIt. -d Shows detail for average. -s Suppresses systemwide counters. -t Specifies tabular output. -c Forces a re-sort of the database. -m Mask Specifies the processor affinity mask. Command Specifies the command to time.
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:
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.