当月份和日期等于或小于 9 时,如何让美国文化信息 (en-US) 显示为带有 2 位小数的 mm/DD/yyyy?我想将日期显示为 09/03/2012 而不是 9/3/2012?请解释它是如何工作的,并提供一个准确的答案。谢谢!
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
$objForm = New-Object Windows.Forms.Form
$objForm.Text = "Select a Date"
$objForm.Size = New-Object Drawing.Size @(190,190)
$objForm.StartPosition = "CenterScreen"
$objForm.KeyPreview = $True
$objForm.Add_KeyDown({
if ($_.KeyCode -eq "Enter")
{
$dtmDate=$objCalendar.SelectionStart
$objForm.Close()
}
})
$objForm.Add_KeyDown({
if ($_.KeyCode -eq "Escape")
{
$objForm.Close()
}
})
$us = New-Object system.globalization.cultureinfo("en-US")
$objCalendar = New-Object System.Windows.Forms.MonthCalendar
$objCalendar.ShowTodayCircle = $False
$objCalendar.MaxSelectionCount = 1
$objForm.Controls.Add($objCalendar)
$objForm.Topmost = $True
$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()
$finaldate = $dtmdate | Get-Date -format ($us.DateTimeFormat.ShortDatePattern)
Write-Host $finaldate