The date format may vary, depending on the operating system:
Tuesday 2008-07-29
2008-07-29 Tuesday
07/29/2008 Tue
Tue 07/29/2008
Taking into account the operating system in languages other than Chinese and English, there are too many types of date formats.
To standardize the current system date 2008-07-28, the direct interception of%date% variables is not possible.
"Scheme one" BAT + REG
@echo
off REM does not guarantee correct results on operating systems in languages other than China
for/f "delims="%%a in (' reg query ' Hkey_current_user/control panel/ International '/V sshortdate ') do (
set "Regdateold=%%a"
)
set regdateold=%regdateold:~-8%
reg ADD " Hkey_current_user/control panel/international "/V sshortdate/t reg_sz/d yyyy-m-d/f>nul
set Today=%date: =%
reg ADD "Hkey_current_user/control panel/international"/V sshortdate/t reg_sz/d%regdateold%/f>nul
Set "W Eek=mon Tue Wed Thu Fri Sat Sun Monday Tuesday Wednesday Thursday Friday Saturday Sunday "for
%%a in (%week%) does (call
set today=%%today:%% a=%% "
)
echo,%today%
Pause
"Scheme two" BAT + REG
@echo off
for/f "delims="%%a in (' reg query ' Hkey_current_user/control panel/international '/V sshortdate ') do (
set "Regdateold=%%a"
)
set regdateold=%regdateold:~-8%
reg add "Hkey_current_user/control panel/ International "/V sshortdate/t reg_sz/d yyyy-m-d/f>nul
set today=%date: =%
REG Add" hkey_current_user/contr OL panel/international "/V sshortdate/t reg_sz/d%regdateold%/f>nul
If"%today:~0,1% "GTR" 9 "(
set Today=%t oday:~-10%
) Else (
set today=%today:~0,10%
)
echo,%today%
Pause
"Scheme three" BAT + REG
@echo off
for/f "delims="%%a in (' reg query ' Hkey_current_user/control panel/international '/V sshortdate ') do (
set "Regdateold=%%a"
)
set regdateold=%regdateold:~-8%
reg add "Hkey_current_user/control panel/ International "/V sshortdate/t reg_sz/d yyyy-m-d/f>nul
type nul>"%temp%/myfile.tmp "for/f
%%a in (' dir ') %temp%/myfile.tmp "^| findstr/i "Myfile.tmp") do (
set today=%%a
)
reg add "Hkey_current_user/control panel/international"/V sshortdate/t reg_sz/d%regdateold%/f>nul
echo,%today%
Pause
"Scheme four" BAT + WMIC
@echo off
for/f "tokens=2 delims=="%%a in (' WMIC path Win32_OperatingSystem get Localdatetime/value ') do (
SE T t=%%a
)
set today=%t:~0,4%-%t:~4,2%-%t:~6,2%
echo,%today%
Pause
"Scheme five" BAT + VBS
@echo off
> "%temp%/datecalculate.vbs" Echo dt=date ()
>> "%temp%/datecalculate.vbs" Echo s=right ( Year (DT), 4) ^& "-" ^& Right ("0" ^& month (DT), 2) ^& "-" ^& Right ("0" ^& Day (DT), 2)
>> "%te" Mp%/datecalculate.vbs "Echo WScript.Echo S
for/f%%a in (' Cscript/nologo"%temp%/datecalculate.vbs "') do set (
T Oday=%%a
)
echo,%today%
Pause
"Scheme six" BAT + REGEDIT
@echo off
REM need to ensure Registry Editor is not locked
regedit/e "%temp%/bak.reg" "Hkey_current_user/control panel/international"
> "%temp%/new.reg" echo REGEDIT4
>> "%temp%/new.reg" Echo,
>> "%temp%/new.reg" Echo [HKEY_ Current_user/control panel/international]
>> "%temp%/new.reg" echo "sshortdate" = "Yyyy-mm-dd"
regedit /S "%temp%/new.reg"
set today=%date: =%
regedit/s "%temp%/bak.reg"
if "%today:~0,1%" GTR "9" (
set today=%today:~-10%
) Else (
set today=%today:~0,10%
)
echo,%today%
Pause
"Scheme seven" BAT + DEBUG
@echo off
for/f "tokens=6,8 delims=="%%a in (' ^ "(echo a100^&echo mov ah^,2a^&echo int 21^&echo.^&ec Ho P 2^&echo q^) ^|debug^|find "CX") do (
set/a y=0x%%a
set md=%%b
)
set/a m=0x%md:~,2%
SE t/a d=0x%md:~-2%
set m=0%m%
set d=0%d%
set today=%y%-%m:~-2%-%d:~-2%
echo,%today%
Pause