How to generate file name according to datetime in bat command
2016-08-26 22:26
435 查看
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
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 Mount and Unmount Filesystem / Partition in Linux (Mount/Umount Command Examples)
- how to query name server with command line in Windows.
- How to generate a log file in VC++ or Embedded VC++ (For Pocket PC or WinCE devices)
- How To Generate An XML File As A Target Datastore Using ODI In An Integration Interface ? [ID 454268
- How to run a _BAT file in InstallShield
- How to change the name in open with list / File association.
- How to get real file offset in NAND by file name?
- How to find a file or folder in MS-DOS or Windows command line
- How to decompile class file in Java and Eclipse - Javap command example(转)
- How to do sleep in bat file
- How to Take Ownership of a File/Folder Using Command-Line in Windows 7 or newer version System
- How to create and execute JAR file in Java – Command line Eclipse Netbeans
- How to run a .BAT file in InstallShield?
- Shell: how to list all db links in oracle DB to generate a flat file (生成dblink列表文件)
- how to using CommandArgument in DataGrid
- JSTL的问题(According to TLD or attribute directive in tag file, attribute value does not accept any expressions)
- How to read Mac .DMG file in Linux or PC
- How to read Mac .DMG file in Linux or PC(II)
- JSP中出现According to TLD or attribute directive in tag file, attribute value does not accept any expressions(转贴)
- How to execute system command in MSSQL