Windows 7批处理文件日期问题
我在 Windows XP 中工作,现在迁移到 Windows 7。使用批处理文件来构建。现在不行了。
Windows XP:
echo %DATE:~4,2%-%DATE:~7,2%-%DATE:~10,4%
02-10-2011
Windows-7:
echo %DATE:~4,2%-%DATE:~7,2%-%DATE:~10,4%
2--01-
请帮忙。谢谢。
I worked in windows XP and moved to windows 7 now. Used batch files to build. Now it doesn't work.
Windows XP:
echo %DATE:~4,2%-%DATE:~7,2%-%DATE:~10,4%
02-10-2011
Windows-7:
echo %DATE:~4,2%-%DATE:~7,2%-%DATE:~10,4%
2--01-
Please help. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这对我有用。但是当我尝试这样做时:
它显示:
所以我的猜测是在您的 Windows 7 环境中
%DATE%
必须以与 WinXP 中以前不同的格式返回日期。您可能想要更改脚本或更改日期/时间的区域设置。It works for me. But when I tried this:
it displayed:
So my guess is in your Windows 7 environment
%DATE%
must be returning the date in a different format from what it used to be in WinXP. You might want to change the script or to change locale settings for date/time.我敢打赌 %DATE% 的输出/格式已经改变 - 它受到语言环境/区域设置的影响。
只需执行
echo %DATE%
即可查看格式是否已从 WinXP 更改为 Win7。I bet the output/format of %DATE% has changed - it's affected by locale/regional setting.
Just do an
echo %DATE%
to see if the format has changed from WinXP to Win7.这取决于您的时间设置,时间格式可能会有所不同。
在两者上简单地尝试一下这一行:
最常用的是 DD/MM/YYYY 或 MM/DD/YYYY。
如果不同,则根据需要解析您的字符串。
It depends on your time setting, the time format may be different.
Try simply this line on both:
The most used are DD/MM/YYYY or MM/DD/YYYY.
Than, if different, parse your string as needed.
我刚刚想通了这一点。问题是Win7从0开始计数字符串,而不是XP中的1,所以解决方案是:
XP
WIN7
尝试一下,这对我有用。
I just figured this out. The problem is that Win7 are counting string from 0 instead of 1 in XP, so the solution is:
XP
WIN7
Try it, this works for me.