码迷,mamicode.com
首页 > 其他好文 > 详细

How to generate file name according to datetime in bat command

时间:2016-08-26 22:55:27      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:

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

标签:

原文地址:http://www.cnblogs.com/researcher/p/5811906.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!