I'm writing a batch script and I need the unix time. It's easy under linux, but I can't figure out how to do this in windows.
相关问题
- Inheritance impossible in Windows Runtime Componen
- how to get running process information in java?
- Is TWebBrowser dependant on IE version?
- JQ: Select when attribute value exists in a bash a
- How can I have a python script safely exit itself?
相关文章
- 如何让cmd.exe 执行 UNICODE 文本格式的批处理?
- 怎么把Windows开机按钮通过修改注册表指向我自己的程序
- Warning : HTML 1300 Navigation occured?
- Check if directory exists on remote machine with s
- Bundling the Windows Mono runtime with an applicat
- Windows 8.1 How to fix this obsolete code?
- Reverse four length of letters with sed in unix
- Compile and build with single command line Java (L
Here is a native batch solution that should work in any locale. It uses WMIC to get the current local time in a locale independent manner. Everything else is a "simple" matter of string parsing and basic math.
Note that this solution has a limited life span. It will cease to work on 2038-01-19 when the Unix time exceeds the maximum value of a signed 32 bit integer.
EDIT - The code has been edited to support conversion of a timestamp string on the command line instead of the current local time. The precise range of times supported is 1901-12-13 20:45:52.000000 through 2038-01-19 03:14:07.999999 GMT. Times prior to 1970-01-01 00:00:00.000000 will yield negative values.
If by "unix time" you mean the epoch second, then Windows doesn't include tools to produce that. Instead, you can install third-party tools. For example:
date
binary (underC:\Cygwin\
or wherever you installed it)Alternately, per the awesome comment on this answer, you could install GNU Coreutils which also include a
date
command. It includes a number of other tools that you may not need, but then, so does Cygwin.You can use vbscript in windows, the interpreter is available on your system.