Change date and time format via command prompt

2019-07-14 19:01发布

问题:

I was just wondering, in Windows 7 and above, is it possible to change the way dates and times are displayed via the command prompt? Yes, I'm in the U.S. but I like doing things the European way:

(In Clock/Language/Region)

Short Date: Set as "d/M/yyyy"

Long Date: Set as "dddd, d MMMM yyyy"

Short Time: Set as "HH:mm"

Long Time: Set as "HH:mm:ss"

回答1:

Yes, it's possible e.g. using reg add command.
Check the HKEY_CURRENT_USER\Control Panel\International registry key:

reg query "HKCU\Control Panel\International"

For instance, query Short Time format:

reg query "HKCU\Control Panel\International" /V sShortTime

and set it to desired value:

reg add "HKCU\Control Panel\International" /V sShortTime /T REG_SZ /D HH:mm /F

If value name or data contains spaces, use double quotes (surrounding double quotes would not be written to registry):

reg add "HKCU\Control Panel\International" /V sShortTime /T REG_SZ /D "HH:mm" /F


回答2:

X:>echo %date:~10,4%%date:~4,2%%date:~7,2% 20181110