批处理文件:获取格式昨天的日期:M_D_YYYY [英] Batch file: Get yesterday's date in format: M_d_yyyy

查看:224
本文介绍了批处理文件:获取格式昨天的日期:M_D_YYYY的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

怎样才能获得昨天的日期格式的批处理文件?

How does one get yesterday's date format in a batch file?

我想它看起来像这样: M_D_YYYY

I'd like it to look like so: M_d_yyyy

请注意,如果有一个单一的数字日期和月份,我想它是个位数。

Note that if there's a single digit day and month, I'd like it to be single digits.

例如: 8_5_2013 2013年8月5日

我四处张望了好几天也没有找到一个解决方案..任何铅是多少AP preciated。

I looked around for a few days but couldn't find a solution.. any lead is much appreciated.

推荐答案

我觉得你应该从的 UnxUtils 的。

date.exe --date =1天前+% - M_%D_%Y

下载地址: http://sourceforge.net/projects/unxutils/files/unxutils /电流/ 结果
手册页: http://www.ss64.com/bash/date.html

@echo off
setlocal
set magic="c:\unx\usr\local\wbin\date.exe" --date="1 day ago" "+%%-m_%%d_%%Y"
for /f %%i in ('%magic%') do set yesterdate=%%i
echo yesterdate = %yesterdate%


如果您想只用批处理语言做,你最终会拥有近的 100线INCOM prehensible一批code 的。 更新:或使用dbenham的混合批次/ JScript的解决方案张贴在下面的答案,其中至少使用了理智的Windows API


If you want to do it with just batch language, you'll end up with nearly 100 lines of incomprehensible batch code. UPDATE: or use dbenham's hybrid batch/JScript solution posted in the answer below, which at least uses sane Windows APIs.

另请参见:
<一href=\"http://stackoverflow.com/questions/203090/how-to-get-current-datetime-on-windows-command-line-in-a-suitable-format-for-us\">How以获得在Windows命令行当前日期时间,以合适的格式用于使用在一个文件名?

这篇关于批处理文件:获取格式昨天的日期:M_D_YYYY的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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