Windows 7 batch file date Issue
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:
开发者_JAVA技巧echo %DATE:~4,2%-%DATE:~7,2%-%DATE:~10,4%
2--01-
Please help. Thanks.
It works for me. But when I tried this:
SET DATF=2011-10-02
ECHO %DATF:~4,2%-%DATF:~7,2%-%DATF:~10,4%
it displayed:
-1--0-
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.
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.
It depends on your time setting, the time format may be different. Try simply this line on both:
echo %DATE%
The most used are DD/MM/YYYY or MM/DD/YYYY.
Than, if different, parse your string as needed.
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
echo %DATE:~4,2%-%DATE:~7,2%-%DATE:~10,4%
WIN7
echo %DATE:~3,2%-%DATE:~6,2%-%DATE:~9,4%
Try it, this works for me.
精彩评论