获得YYYYMMDD格式的日期在Windows批处理文件 [英] Get Date in YYYYMMDD format in windows batch file

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

问题描述

我需要在批处理文件YYYYMMDD格式的日期。

I need to get the date in YYYYMMDD format in batch file.

我做这个使用:

set mydate=%date:~6,4%%date:~3,2%%date:~0,2%
echo %mydate%

我需要它是整个系统保持一致,甚至在改变时间设置。

I need it to be consistent across system, even on changing the time settings.

请指教。

推荐答案

如果,阅读其他问题和查看在注释部分中提到的链接之后,你仍然无法搞清楚,请继续阅读。

If, after reading the other questions and viewing the links mentioned in the comment sections, you still can't figure it out, read on.

首先,你要去哪里错了是偏移量。

First of all, where you're going wrong is the offset.

它应该看起来更像这个...

It should look more like this...

set mydate=!date:~10,4!!date:~6,2!/!date:~4,2!
echo %mydate%

如果日期是周二2013年12月2日那么它会显示为 2013年2月12日 。去掉一个斜杠,code看起来更像设置数值指明MyDate =日期:〜!10,4 !!日期:7,2〜!!日期:〜!4,2 这将输出 20130212 ,它看起来并不像一个日期事情。

If the date was Tue 12/02/2013 then it would display it as 2013/02/12. to remove the slashes, the code would look more like set mydate=!date:~10,4!!date:~7,2!!date:~4,2! which would output 20130212, which doesn't look anything like a date.

和做它在未来,如果数值指明MyDate 等于像日期提示:!〜10,4 !!日期:7〜 2!或类似的,你可能忘了一个符号(〜)。

And a hint for doing it in the future, if mydate equals something like !date:~10,4!!date:~7,2! or the like, you probably forgot a tilde (~).

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

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