Different operating systems may also have different date formats:
Tuesday 2008-07-29
2008-07-29 Tuesday
07/29/2008 Tue
Tue 07/29/2008
Considering operating systems in other languages other than Chinese and English, there are too many types of date formats.
To obtain the current system date 2008-07-28 in a standardized manner, the method of directly intercepting the %date% variable is not possible.
【Program 1】BAT + REG
@echo off rem There is no guarantee that it is in、Get correct results on operating systems in other languages other than English 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 "Week=Mon Tue Wed Thu Fri Sat Sun Monday Tuesday Wednesday Thursday Friday Saturday Sunday" for %%a in (%Week%) do ( call set "Today=%%Today:%%a=%%" ) echo,%Today% pause
【Scheme 2】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/Control Panel/International" /v sShortDate /t REG_SZ /d %RegDateOld% /f>nul if "%Today:~0,1%" gtr "9" ( set Today=%Today:~-10% ) else ( set Today=%Today:~0,10% ) echo,%Today% pause
【Scheme 3】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%/" for /f %%a in ('dir "%temp%/" ^| findstr /i ""') 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 4】BAT + WMIC
@echo off for /f "tokens=2 delims==" %%a in ('wmic path win32_operatingsystem get LocalDateTime /value') do ( set t=%%a ) set Today=%t:~0,4%-%t:~4,2%-%t:~6,2% echo,%Today% pause
【Scheme 5】BAT + VBS
@echo off >"%temp%/" echo dt=date() >>"%temp%/" echo s=right(year(dt),4) ^& "-" ^& right("0" ^& month(dt),2) ^& "-" ^& right("0" ^& day(dt),2) >>"%temp%/" echo s for /f %%a in ('cscript /nologo "%temp%/"') do set ( Today=%%a ) echo,%Today% pause
【Scheme VI】BAT + REGEDIT
@echo off rem It is necessary to ensure that the registry editor is not locked regedit /e "%temp%/" "HKEY_CURRENT_USER/Control Panel/International" >"%temp%/" echo REGEDIT4 >>"%temp%/" echo, >>"%temp%/" echo [HKEY_CURRENT_USER/Control Panel/International] >>"%temp%/" echo "sShortDate"="yyyy-MM-dd" regedit /s "%temp%/" set Today=%date: =% regedit /s "%temp%/" if "%Today:~0,1%" gtr "9" ( set Today=%Today:~-10% ) else ( set Today=%Today:~0,10% ) echo,%Today% pause
【Scheme 7】BAT + DEBUG
@echo off for /f "tokens=6,8 delims== " %%a in ('^(echo a100^&echo mov ah^,2a^&echo int 21^&echo.^&echo p 2^&echo q^)^|debug^|find "CX"') do ( set /a y=0x%%a set md=%%b ) set /a m=0x%md:~,2% set /a d=0x%md:~-2% set m=0%m% set d=0%d% set Today=%y%-%m:~-2%-%d:~-2% echo,%Today% pause