如何使用dos批处理文件命令将日期设置为当前日期 [英] how to set date to current date using dos batch file command

查看:184
本文介绍了如何使用dos批处理文件命令将日期设置为当前日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用dos批处理文件命令将日期设置为当前日期.

how to set date to current date using dos batch file command.

推荐答案

如果需要在批处理文件中使用当前日期,则变量%date%具有当前日期:

If you need to use the current date in a batch file, the variable %date% has the current date:

echo %date%
23/02/2010

它使用计算机区域设置的格式.在我的计算机上是dd/mm/yyyy.

It uses the format of the regional setting of your computer. In my computer it's dd/mm/yyyy.

由于/不能是文件名的一部分,因此必须将其替换为安全字符或什么都不能替换:

Since the / can't be part of a file name, they must be replaced with a safe character or nothing:

echo %date:/=-%
23-02-2010

echo %date:/=%
23022010

如果要创建文件的备份副本,则可以执行以下操作:

If you want to create a backup copy of a file, you can do something like:

copy file.txt file-%date:/=%.txt
dir /b file*.*
file-23022010.txt
file.txt

或首先将其设置为变量,然后使用它:

Or first set it to a variable and then use it:

set currdate=%date:/=%
copy file.txt file-%currdate%.txt

这篇关于如何使用dos批处理文件命令将日期设置为当前日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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