Created
April 11, 2018 18:04
-
-
Save gitfvb/65d7585ed46ac265caee50e2640b5960 to your computer and use it in GitHub Desktop.
use another locale e.g. for outputting a date string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# cool function to create a date output in another locale | |
# SOURCE: https://stackoverflow.com/questions/2379514/powershell-formatting-values-in-another-culture | |
function Using-Culture ([System.Globalization.CultureInfo]$culture =(throw "USAGE: Using-Culture -Culture culture -Script {scriptblock}"), | |
[ScriptBlock]$script=(throw "USAGE: Using-Culture -Culture culture -Script {scriptblock}")) | |
{ | |
$OldCulture = [System.Threading.Thread]::CurrentThread.CurrentCulture | |
$OldUICulture = [System.Threading.Thread]::CurrentThread.CurrentUICulture | |
try { | |
[System.Threading.Thread]::CurrentThread.CurrentCulture = $culture | |
[System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture | |
Invoke-Command $script | |
} | |
finally { | |
[System.Threading.Thread]::CurrentThread.CurrentCulture = $OldCulture | |
[System.Threading.Thread]::CurrentThread.CurrentUICulture = $OldUICulture | |
} | |
} | |
Using-Culture en-GB { Get-Date -format "ddd, dd MMM yyyy HH:mm:ss zz00" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment