简体   繁体   English

如何将时间附加到此命令提示符date命令

[英]How can I append time to this command prompt date command

I am trying to run a .bat file with command prompt to add time to the date. 我正在尝试使用命令提示符运行.bat文件以将时间添加到日期。

Currently, I have this code 目前,我有此代码

MOVE...\folder\^"Mytest %DATE:/=-%.csv^"

This produces 这产生

..\folder\Mytest Thu 12-06-2012.csv

I want to get 我想得到

..\folder\Mytest Thu 12-06-2012 21:45.csv

Tried all kinds of things but failed miserably. 尝试了各种事情,但失败了。 Help would be greatly appreciated. 帮助将不胜感激。

This will work: 这将起作用:

 %date:/=-% %time:~0,5%.csv

The %time% uses the current time; %time%使用当前时间; the :~ means "a substring of", and the 0,5 says "starting at the first character (index 0) and continuing for 5 characters", so the entire thing means "give me the first 5 characters of the output of time ". :~表示“的子字符串”,而0,5表示“从第一个字符(索引0)开始并持续5个字符”,因此整个意思是“给我time输出的前5个字符”。

Using this at a command prompt: 在命令提示符下使用此命令:

C:\>echo %date:/=-% %time:~0,5%

outputs 输出

Thu 12-06-2012 18:19

The format you're using is going to cause problems with sorting, though. 但是,您使用的格式将导致排序问题。 My advice would be to drop the day of the week portion, and change the date output to CCYY-MM-DD , which will be much more useful when you're trying to find a specific date. 我的建议是删除星期几部分,并将日期输出更改为CCYY-MM-DD ,这在您尝试查找特定日期时会更加有用。 You can use this: 您可以使用此:

echo %date:~10,4%-%date:~4,2%-%date:~7,2% %time:~0,5%

which outputs 哪个输出

2012-12-06 18:33

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM