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

时间: 2024-10-20 10:59:38

How to generate file name according to datetime in bat command的相关文章

E212: Can't open file for writing Press ENTER or type command to continue

E212: Can't open file for writing Press ENTER or type command to continue 出现这个错误的原因可能有两个: 1.当前用户的权限不足 2.此文件可能正被其他程序或用户使用. 一般错误原因都是前者,解决方案是在使用vi命令打开文件时,前面加上sudo来临时提供管理员权限,比如使用命令"sudo vi hosts"打开编辑文件. 由此看来,sudo命令是很有用的,当我们执行某种操作系统提示诸如"operatio

vi编辑文件保存后,提示""vimrc" E212: Can't open file for writing Press ENTER or type command to continu"

出现这个错误的原因可能有两个: 1.当前用户的权限不足: 2.此文件可能正被其他程序或用户使用. 一般错误原因都是前者,解决方案是在使用vi命令打开文件时,前面加上sudo来临时提供管理员权限,比如使用命令“sudo vi vimrc”打开编辑文件. vi编辑文件保存后,提示""vimrc" E212: Can't open file for writing Press ENTER or type command to continu" 原文地址:https://w

ZOJ File Searching(字符串)

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1840 Have you ever used file searching tools provided by an operating system? For example, in DOS, if you type "dir *.exe", the OS will list all executable files with extension &quo

转载)Detecting the File Download Dialog In the Browser

Detecting the File Download Dialog In the Browser Web applications sometimes need to create documents (PDF, Excel, Word, TIFF, etc.) based on some user input. In most cases, these documents are fairly simple and quick to create, allowing us to create

Update files embedded inside CAB file.

References: https://community.flexerasoftware.com/showthread.php?182791-Replace-a-single-file-embedded-in-an-MSI Windows Installer Scripting Examples WiFilVer.vbs : Manage File Sizes and Versions WiMakCab.vbs: Generate File Cabinet @ECHO administrati

linux操作提示:“Can't open file for writing”或“operation not permitted”的解决办法

在linux上使用vi命令修改一个文件内容的时候,发现无法保存,每次写完使用":q!"命令可以正常退出但是使用":wq!"命令保存文件并退出时出现一下信息提示: E212: Can't open file for writing Press ENTER or type command to continue 出现这个错误的原因可能有两个:    1.当前用户的权限不足    2.此文件可能正被其他程序或用户使用.      一般错误原因都是前者,解决方案是在使用vi

Git Tutorial 7 - File States

File States Overview Every file in your working directory is mainly in one of 2 states: 1. Tracked : All files that were committed to the last snapshot in Git repository are in state Tracked. They can be one of the following states: 1.1 Unmodified : 

File Compression and Archiving in linux (linux 中文件的归档)

1. Compressing Files at the Shell Prompt Red Hat Enterprise Linux provides the bzip2, gzip, and zip tools for compression from a shell prompt. The bzip2 compression tool is recommended because it provides the most compression and is found on most UNI

SaltStack源码分析之file状态模块

file模块用于对普通文件,目录,特殊文件和链接文件进行各种操作 /usr/lib/python2.6/site-packages/salt/states/file.py def managed(name,             source=None,             source_hash='',             user=None,             group=None,             mode=None,             template=No