1. Customizing your date using -Format
or -UFormat
You can use the -Format
or the -UFormat
paramater to enforce a certain layout of your date:
Get-Date -Format "dddd, d MMMM yyyy hh:mm:ss tt"
Get-Date -UFormat "%A, %e %B %Y %r"
Both will display your desired date format, as long as you are using en-US
culture information:
Wednesday, 15 April 2020 08:09:24 AM
Learn more about:
2. Customizing your date with different culture information
If you want to display the date in a different language, you can also enforce a certain culture information. Keep in mind that the -Format
parameter is just a wrapper for the ToString()
method. So you can also use the following line to display your date as desired:
(Get-Date).ToString('dddd, d MMMM yyyy hh:mm:ss tt')
Fortunately, there exist different overloads of that ToString()
method. There is also one, that takes culture information as a second parameter. So in conclusion you can pass different culture info to your ToString()
method to get results in different languages:
$culture = [System.Globalization.CultureInfo]::CreateSpecificCulture('en-US')
(Get-Date).ToString('dddd, d MMMM yyyy hh:mm:ss tt', $culture)
will display:
Wednesday, 15 April 2020 08:09:24 AM
and at the same time
$culture = [System.Globalization.CultureInfo]::CreateSpecificCulture('de-DE')
(Get-Date).ToString('dddd, d MMMM yyyy hh:mm:ss tt', $culture)
will display:
Mittwoch, 15 April 2020 08:09:24
3. Customizing your date with predefined culture specific patterns
In $culture.DateTimeFormat
you can also find already prepared culture specific patterns to format your date and you can use them instead of writing them on your own:
$culture = [System.Globalization.CultureInfo]::CreateSpecificCulture('en-US')
(Get-Date).ToString($culture.DateTimeFormat.ShortDatePattern, $culture)
will display:
4/15/2020
and at the same time
$culture = [System.Globalization.CultureInfo]::CreateSpecificCulture('de-DE')
(Get-Date).ToString($culture.DateTimeFormat.ShortDatePattern, $culture)
will display:
15.04.2020
Btw: A similar pattern to yours, specified in your question, would be:
$culture = [System.Globalization.CultureInfo]::CreateSpecificCulture('en-US')
(Get-Date).ToString($culture.DateTimeFormat.FullDateTimePattern, $culture)
Wednesday, April 15, 2020 8:09:24 AM