none
date-format in different cultures RRS feed

  • Question

  • On my Dutch PC I would like to have the date displayed in en-US format, i.e. 12/31/2017 instead of 31-12-2017.

    I'm using Ed Wilsons script on https://blogs.technet.microsoft.com/heyscriptingguy/2011/08/25/use-culture-information-in-powershell-to-format-dates/ which is supposed to do exactly what I want, but it doesn't:

    PS C:\>get-culture

    LCID             Name             DisplayName
    ----             ----             -----------
    1043             nl-NL            Dutch (Netherlands)

    But for all Cultures it shows a dash instead of a slash as separator character:

    $cultures = “en-US”,”en-GB”,”fr-CA”,”fr-FR”,”ms-MY”,”zh-HK”

    foreach ($c in $cultures)

    {

     $culture = New-Object system.globalization.cultureinfo($c)

     $date = get-date -format ($culture.DateTimeFormat.ShortDatePattern)

     New-Object psobject -Property @{“name”=$culture.displayname; “date”=$date}

    }

    Shows:

    name                                    date
    ----                                    ----
    English (United States)                 4-11-2017
    English (United Kingdom)                11-04-2017
    French (Canada)                         2017-04-11
    French (France)                         11-04-2017
    Malay (Malaysia)                        11-04-2017
    Chinese (Traditional, Hong Kong S.A.R.) 11-4-2017

    Why? And how do I get a slash?

    (yes, I know I could use the -format parameter of get-date to specify the date format, but that's not the question)


    • Edited by Sam Balby Tuesday, April 11, 2017 1:31 PM
    Tuesday, April 11, 2017 1:30 PM

Answers

  • D:\scripts> [cultureinfo]::CurrentCulture.DateTimeFormat.DateSeparator = '-'
    D:\scripts> [datetime]::Now.ToShortDateString()
    4-11-2017

    \_(ツ)_/

    • Marked as answer by Sam Balby Thursday, April 13, 2017 6:06 AM
    Tuesday, April 11, 2017 2:02 PM

All replies

  • [cultureinfo]::CreateSpecificCulture('en-US').DateTimeFormat.ShortDatePattern

    \_(ツ)_/

    Tuesday, April 11, 2017 1:58 PM
  • D:\scripts> [cultureinfo]::CurrentCulture.DateTimeFormat.DateSeparator = '-'
    D:\scripts> [datetime]::Now.ToShortDateString()
    4-11-2017

    \_(ツ)_/

    • Marked as answer by Sam Balby Thursday, April 13, 2017 6:06 AM
    Tuesday, April 11, 2017 2:02 PM