Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing Windows Time and Date Format

Tags:

powershell

I'd like to automate preferences on a Windows machine for the date and time formats used throughout the OS.

What PowerShell commands can I use to automate this task of changing values?

  • short date format
  • short and long time format

These options are buried deep in Control Panel.

enter image description here

enter image description here

like image 880
p.campbell Avatar asked Feb 26 '15 17:02

p.campbell


3 Answers

I believe the settings you are looking for are located in:

HKEY_CURRENT_USER\Control Panel\International\sLongDate
HKEY_CURRENT_USER\Control Panel\International\sShortDate
HKEY_CURRENT_USER\Control Panel\International\sTimeFormat
HKEY_CURRENT_USER\Control Panel\International\sYearMonth

So,

Set-ItemProperty -Path "HKCU:\Control Panel\International" 
                 -name sLongDate -value "<Whatever format you'd like>"
like image 108
puc Avatar answered Oct 18 '22 03:10

puc


Based on p.campbells's answer, but with all properties:

Set-ItemProperty -Path "HKCU:\Control Panel\International" -Name sCountry -Value "Germany";
Set-ItemProperty -Path "HKCU:\Control Panel\International" -Name sLongDate -Value "dddd, d. MMMM yyyy";
Set-ItemProperty -Path "HKCU:\Control Panel\International" -Name sShortDate -Value "dd.MM.yyyy";
Set-ItemProperty -Path "HKCU:\Control Panel\International" -Name sShortTime -Value "HH:mm";
Set-ItemProperty -Path "HKCU:\Control Panel\International" -Name sTimeFormat -Value "HH:mm:ss";
Set-ItemProperty -Path "HKCU:\Control Panel\International" -Name sYearMonth -Value "MMMM yyyy";
Set-ItemProperty -Path "HKCU:\Control Panel\International" -Name iFirstDayOfWeek -Value 0;
like image 43
michidk Avatar answered Oct 18 '22 05:10

michidk


Full example based on p.campbell's answer:

Set-ItemProperty -Path "HKCU:\Control Panel\International" -Name sCountry -Value "Germany";
Set-ItemProperty -Path "HKCU:\Control Panel\International" -Name sLongDate -Value "dddd, d. MMMM yyyy";
Set-ItemProperty -Path "HKCU:\Control Panel\International" -Name sShortDate -Value "dd.MM.yyyy";
Set-ItemProperty -Path "HKCU:\Control Panel\International" -Name sShortTime -Value "HH:mm";
Set-ItemProperty -Path "HKCU:\Control Panel\International" -Name sTimeFormat -Value "HH:mm:ss";
Set-ItemProperty -Path "HKCU:\Control Panel\International" -Name sYearMonth -Value "MMMM yyyy";
Set-ItemProperty -Path "HKCU:\Control Panel\International" -Name iFirstDayOfWeek -Value 0;

To set the settings of the default user instead of the system, use HKU:\.DEFAULT\Control Panel\International. For a specific user use HKU:\(UserSID)\Control Panel\International.

To get the SID of the current user, use

([System.Security.Principal.WindowsIdentity]::GetCurrent()).User.Value

If you don't have HKU: mapped, use

New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS
like image 43
MovGP0 Avatar answered Oct 18 '22 03:10

MovGP0