For all I know, Batch does not have a command that gives the UNIX time. The closest one I can find is %time%
, which only displays the timestamp.
Is there a command, or set of commands in Batch with which you can get the UNIX time?
For all I know, Batch does not have a command that gives the UNIX time. The closest one I can find is %time%
, which only displays the timestamp.
Is there a command, or set of commands in Batch with which you can get the UNIX time?
There's Richie Lawrence's batch library that has all those nifty handy scripts. The one you need is DateToSec (which uses GetDate and GetTime).
Here's a simplified script, that employs a little WMI:
The result will be returned into the first parameter passed to
GetUnixTime
, i.e.%UNIX_TIME%
.For example:
Hope it helps!
By far best solution is to download a freestanding date.exe unix-port.
Recommend that you rename it to unixdate.exe, to avoid conflict with MS Date command.
Get it from here
Example:
What about simple 1-line long C program returning UNIX timestamp? You can retrieve value from %errorlevel% in batch script.
In my test in command prompt it worked:
There is no batch command for returning UNIX time. Your only options would be to write a program which could be run from a batch file that would return the UNIX time, or you could use the Windows PowerShell.
create a .bat file called "getUtime.bat"
and call like this