Windows – How to change date/time format via command prompt/powershell

command linewindowswindows 10

I'm trying to automate my PC setup as much as possible and I'm wondering if it's possible to change the date/time format via the command line.

If yes, I would like to know the command.

Best Answer

The date/time format is encoded as part of the region. You can set this from the CLI via the PowerShell Set-Culture cmdlet. This is part of the International module available since Windows 8/Server 2012. You are basically looking for the equivalent of the GUI Control Panel Region applet (which can be displayed with control /name Microsoft.RegionAndLanguage).


Example

For the impatient, the basic PowerShell command is:

$culture = Get-Culture
$culture.DateTimeFormat.ShortDatePattern = 'd/MM/yyyy'
Set-Culture $culture

There are some other date/time patterns I've listed down the bottom that you might wish to modify.


Details

First, if you're on Windows 8, you'll need to import the module. This is not necessary on Windows 10.

Import-Module International

Now, if you wanted to change your entire region, you can do that in a single command, e.g.:

Set-Culture 'en-AU'

You can use any valid BCP-47 tag here. Note that this will also change other region-related settings, such as the decimal separator.

This is the approach I would recommend most of the time, unless you have specific needs otherwise.


If you want to more specifically control the date/time format, you'll need to either construct your own CultureInfo object or take the current culture and modify it:

$culture = Get-Culture
$culture.DateTimeFormat.ShortDatePattern = 'd/MM/yyyy'
Set-Culture $culture

Relevant date/time properties

You can see the list of existing options by just running $culture.DateTimeFormat (or Get-Culture.DateTimeFormat). The ones you might want to modify are:

FullDateTimePattern
LongDatePattern
LongTimePattern
ShortDatePattern
ShortTimePattern

I would recommend not touching the RFC1123 pattern and the sortable patterns.

Related Question