How to generate file name according to datetime in bat command

Posted Researcher

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了How to generate file name according to datetime in bat command相关的知识,希望对你有一定的参考价值。

On the command line, note: must copy and paste below lines of code and then execute them one by one:

FOR /f %a IN (‘WMIC OS GET LocalDateTime ^| FIND "."‘) DO SET DTS=%a
SET DateTime=%DTS:~0,4%-%DTS:~4,2%-%DTS:~6,2%_%DTS:~8,2%-%DTS:~10,2%-%DTS:~12,2%
echo %DateTime%

In a BAT file:

@echo off
REM See http://stackoverflow.com/q/1642677/1143274
FOR /f %%a IN (‘WMIC OS GET LocalDateTime ^| FIND "."‘) DO SET DTS=%%a
SET DateTime=%DTS:~0,4%-%DTS:~4,2%-%DTS:~6,2%_%DTS:~8,2%-%DTS:~10,2%-%DTS:~12,2%
echo %DateTime%

Example output:

2016-08-26_22-21-15

以上是关于How to generate file name according to datetime in bat command的主要内容,如果未能解决你的问题,请参考以下文章

how to generate a SKProduct directly

How to generate an SSH key pair in Windows using PuTTY?

How to image a CD/DVD ROM and generate hash value

simulation -- How to generate samples from UNIFORM

OpenSSL文档阅读笔记-How to Use OpenSSL to Generate RSA Keys in C/C++

How To Determine The Cause Of Lots Of Redo Generation Using LogMiner (Doc ID 300395.1)