[Date and Time] Get the current system date through batch processing Standardization

Source: Internet
Author: User

The date format may vary depending on the operating system:

Tuesday 2008-07-29
Tuesday
07/29/2008 TUE
Tue 07/29/2008

 

Considering the operating systems in other Chinese and English languages, there are too many types of date formats.
To obtain the current system date in a standardized manner, you cannot directly intercept the % date % variable.

 

[Solution 1] bat + Reg

 

@ Echo off <br/> REM cannot guarantee correct results for the operating system in a language other than Chinese or English <br/> for/F "delims =" % A in ('reg query "HKEY_CURRENT_USER/control panel/International"/V s1_date ') do (<br/> set "regdateold = % A" <br/>) <br/> set regdateold = % regdateold :~ -8% <br/> Reg Add "HKEY_CURRENT_USER/control panel/International"/V s1_date/T REG_SZ/d yyyy-m-D/F> NUL <br/> set today = % Date: = % <br/> Reg Add "HKEY_CURRENT_USER/control panel/International"/V s1_date/T REG_SZ/d % regdateold %/F> NUL <br/> set "week = mon tue wed Thu Fri Sat sun Monday Tuesday Thursday Sunday "<br/> for % A in (% week %) do (<br/> call set "today = % today: % A = %" <br/>) <br/> echo, % today % <br/> pause

 

Solution 2: BAT + Reg

 

@ Echo off <br/> for/F "delims =" % A in ('reg query "HKEY_CURRENT_USER/control panel/International"/V s1_date ') do (<br/> set "regdateold = % A" <br/>) <br/> set regdateold = % regdateold :~ -8% <br/> Reg Add "HKEY_CURRENT_USER/control panel/International"/V s1_date/T REG_SZ/d yyyy-m-D/F> NUL <br/> set today = % Date: = % <br/> Reg Add "HKEY_CURRENT_USER/control panel/International"/V s1_date/T REG_SZ/d % regdateold %/F> NUL <br/> If "% today: ~ 0, 1% "gtr" 9 "(<br/> set today = % today :~ -10% <br/>) else (<br/> set today = % today :~ 0, 10% <br/>) <br/> echo, % today % <br/> pause

 

Solution 3: BAT + Reg

 

@ Echo off <br/> for/F "delims =" % A in ('reg query "HKEY_CURRENT_USER/control panel/International"/V s1_date ') do (<br/> set "regdateold = % A" <br/>) <br/> set regdateold = % regdateold :~ -8% <br/> Reg Add "HKEY_CURRENT_USER/control panel/International"/V s1_date/T REG_SZ/d yyyy-m-D/F> NUL <br/> type NUL> "% Temp %/myfile. TMP "<br/> for/F % A in ('dir" % Temp %/myfile. TMP "^ | findstr/I" myfile. TMP "') Do (<br/> set today = % A <br/>) <br/> Reg Add "HKEY_CURRENT_USER/control panel/International"/V s1_date/T REG_SZ/d % regdateold %/F> NUL <br/> echo, % today % <br/> pause

 

Solution 4: BAT + WMIC

 

 @ Echo off <br/> for/F "tokens = 2 delims =" % A in ('wmic path win32_operatingsystem get localdatetime/value ') do (<br/> set T = % A <br/>) <br/> set today = % T :~ 0, 4%-% T :~ 4,2%-% T :~ 6, 2% <br/> echo, % today % <br/> pause

 

Solution 5: BAT + vbs

 

 @ Echo off <br/> "% Temp %/datecalculate. vbs "Echo dt = Date () <br/>" % Temp %/datecalculate. vbs "Echo S = right (Year (DT), 4) ^ &"-"^ & right (" 0 "^ & month (DT), 2) ^ & "-" ^ & right ("0" ^ & Day (DT), 2) <br/> "% Temp %/datecalculate. vbs "Echo wscript. echo S <br/> for/F % A in ('cscript/nologo "% Temp %/datecalculate. vbs "') do set (<br/> today = % A <br/>) <br/> echo, % today % <br/> pause

 

Solution 6: BAT + regedit

 

@ Echo off <br/> REM must ensure that the Registry Editor is not locked <br/> Regedit/E "% Temp %/Bak. reg "" HKEY_CURRENT_USER/control panel/International "<br/>" % Temp %/New. reg "Echo regedit4 <br/>" % Temp %/New. reg "Echo, <br/>" % Temp %/New. reg "Echo [HKEY_CURRENT_USER/control panel/International] <br/>" % Temp %/New. reg "Echo" s0000date "=" yyyy-mm-dd "<br/> Regedit/s" % Temp %/New. reg "<br/> set today = % Date: = % <br/> Regedit/s" % Temp %/B AK. Reg "<br/> If" % today :~ 0, 1% "gtr" 9 "(<br/> set today = % today :~ -10% <br/>) else (<br/> set today = % today :~ 0, 10% <br/>) <br/> echo, % today % <br/> pause

 

Solution 7: BAT + debug

 

@ Echo off <br/> 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 (<br/> set/a y = 0x % A <br/> set MD = % B <br/>) <br/> set/a m = 0x % MD :~, 2% <br/> set/a d = 0x % MD :~ -2% <br/> Set M = 0% M % <br/> set D = 0% d % <br/> set today = % Y %-% m :~ -2%-% d :~ -2% <br/> echo, % today % <br/> pause

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.