Why does PowerShell always use US culture when casting to DateTime?

前端 未结 2 1421
时光说笑
时光说笑 2020-12-11 15:29

When trying to read a CSV yesterday, I noticed that PowerShell seems to always assume US date format when using [datetime]\"date\".

My regional

2条回答
  •  萌比男神i
    2020-12-11 15:35

    You can force the culture for a single command if needed:

    PS C:\> [System.Threading.Thread]::CurrentThread.CurrentUICulture = "en-US" ; [System.Threading.Thread]::CurrentThread.CurrentCulture = "en-US"; [DateTime]::Parse("12/10/2012")
    
    Monday, December 10, 2012 12:00:00 AM
    
    PS C:\> [System.Threading.Thread]::CurrentThread.CurrentUICulture = "en-GB" ; [System.Threading.Thread]::CurrentThread.CurrentCulture = "en-GB"; [DateTime]::Parse("12/10/2012")
    
    12 October 2012 00:00:00
    

提交回复
热议问题