Converting Information to Culture-Specific Text

by Dec 11, 2017

If you’d like to format information to given culture standards, this is really simple by using ToString() and the appropriate target information.

This example takes the current Date and Time, and outputs it in French format:

$date = Get-Date
$frenchCulture = New-Object -TypeName CultureInfo("fr")
$dateString = $date.ToString($frenchCulture)

When you pick the Thai culture, you’ll notice a completely different year as Thailand is using a different calendar model:

$date = Get-Date
$thaiCulture = New-Object -TypeName CultureInfo("th")
$dateString = $date.ToString($thaiCulture)

When you pick a different culture, Windows will also translate and display month and day names accordingly:

$date = Get-Date
$chineseCulture = New-Object -TypeName CultureInfo("zh")
$dateString = $date.ToString('dddd dd.MMMM yyyy',$chineseCulture)

The result would look similar to this:

星期三 01.十一月 2017

Twitter This Tip! ReTweet this Tip!