如何在批处理文件中附加日期 [英] How to append a date in batch files

查看:29
本文介绍了如何在批处理文件中附加日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在批处理文件中有以下行(在旧的 Windows 2000 框上运行):

I have the following line in a batch file (that runs on an old Windows 2000 box):

7z a QuickBackup.zip *.backup

如何将日期附加到 QuickBackup.zip 文件中.因此,如果我今天运行批处理文件,理想情况下,该文件将是 QuickBackup20090514.zip.

How do I append the date to the QuickBackup.zip file. So if I ran the batch file today, ideally, the file would be QuickBackup20090514.zip.

有没有办法做到这一点?

Is there a way to do this?

推荐答案

Bernhard 的回答 需要对我进行一些调整工作,因为%DATE% 环境变量采用不同的格式(如其他地方所述).此外,还缺少一个波浪号 (~).

Bernhard's answer needed some tweaking work for me because the %DATE% environment variable is in a different format (as commented elsewhere). Also, there was a tilde (~) missing.

代替:

set backupFilename=%DATE:~6,4%%DATE:~3,2%%DATE:0,2%

我不得不使用:

set backupFilename=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%

对于日期格式:

c:Scripts>回显 %DATE%

c:Scripts>echo %DATE%

2009 年 5 月 14 日星期四

Thu 05/14/2009

这篇关于如何在批处理文件中附加日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆