cmd脚本中的日期算术 [英] Date arithmetic in cmd scripting
本文介绍了cmd脚本中的日期算术的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要编写一个脚本,将文件名从aDate.txt更改为bDate.txt,其中:
I need to write a script to change a filename from aDate.txt to bDate.txt where:
- aDate是当前系统日期格式为
yyyymmdd 格式 - bDate是当前系统日期 - 格式为
- aDate is the current system date in yyyymmdd format and
- bDate is the current system date - 1 in yyyymmdd format.
我目前有:
set yy=%date:~6,2%
set mm=%date:~3,2%
set dd=%date:~0,2%
if "%date:~6,1%"==" " set yy=0%yy:~1,1%
if "%date:~3,1%"==" " set mm=0%mm:~1,1%
if "%date:~0,1%"==" " set dd=0%dd:~1,1%
SET sys_date=20%yy%%mm%%dd%
ECHO %sys_date%
REM still have to do this bit properly
SET sys_date_yesterday=%sys_date%a
move %sys_date%.txt %sys_date_yesterday%.txt
但我不知道如何做日期-1的事情(除了长风)从一天减去1,如果是= 0
but I have no idea how to do the date -1 thing (other than the long winded) subtract 1 from the day and if that is = 0 then subtract one from the month and set the day = to the last day of the new month and so on for years.
任何想法?
推荐答案
这也有效:
http://www.robvanderwoude.com/datetiment.php#Yesterday
它是非常完整的,它检查注册表的本地日期格式设置,并使用那些在创建昨天的日期。
It is very complete in that it checks the registry for local date format settings and uses those when creating the yesterday date.
这篇关于cmd脚本中的日期算术的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文