您好,登錄后才能下訂單哦!
這篇文章主要介紹“怎么用批處理bat標(biāo)準(zhǔn)化獲取當(dāng)前系統(tǒng)日期”,在日常操作中,相信很多人在怎么用批處理bat標(biāo)準(zhǔn)化獲取當(dāng)前系統(tǒng)日期問(wèn)題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”怎么用批處理bat標(biāo)準(zhǔn)化獲取當(dāng)前系統(tǒng)日期”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!
操作系統(tǒng)不同,日期格式也可能不同:
星期二 2008-07-29
2008-07-29 星期二
07/29/2008 Tue
Tue 07/29/2008
再考慮到中、英之外的其它語(yǔ)言的操作系統(tǒng),日期格式的種類實(shí)在太多了。
要想標(biāo)準(zhǔn)化地獲取當(dāng)前系統(tǒng)日期2008-07-28,直接截取%date%變量的方法是不行的。
【方案一】BAT + REG
@echo off rem 無(wú)法保證在中、英之外的其它語(yǔ)言的操作系統(tǒng)上得到正確結(jié)果 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 星期一 星期二 星期三 星期四 星期五 星期六 星期日" for %%a in (%Week%) do ( call set "Today=%%Today:%%a=%%" ) echo,%Today% pause
【方案二】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
【方案三】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
【方案四】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
【方案五】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) >>"%temp%/DateCalculate.vbs" echo wscript.echo s for /f %%a in ('cscript /nologo "%temp%/DateCalculate.vbs"') do set ( Today=%%a ) echo,%Today% pause
【方案六】BAT + REGEDIT
@echo off rem 需要保證注冊(cè)表編輯器沒(méi)有處于鎖定狀態(tài) 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
【方案七】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
到此,關(guān)于“怎么用批處理bat標(biāo)準(zhǔn)化獲取當(dāng)前系統(tǒng)日期”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注億速云網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。