如何让 Get-Date 生成“/”作为日期分隔符?需要生成以 en-US 为中心的日期格式。看来 PowerShell 将始终使用区域设置,无论指定的格式如何。它在我的系统上设置为“-”,但我需要使用“/”生成日期。
PS C:\src> Get-Date -Format MM/dd/yyyy
06-26-2017
PS C:\src> Get-Date -Format "MM/dd/yyyy"
06-26-2017
PS C:\src> Get-Date -Format 'MM/dd/yyyy'
06-26-2017
PS C:\src> Get-Date -Format "MM`/dd`/yyyy"
06-26-2017
Run Code Online (Sandbox Code Playgroud)
在我的机器上,日期分隔符设置为“-”。我没有找到 Set-UICulture 命令。
PS C:\src> (Get-UICulture).DateTimeFormat.DateSeparator
-
Run Code Online (Sandbox Code Playgroud)
在格式字符串中,/表示当前 UICulture 日期分隔符。要强制它显式为该/字符,您必须使用该\字符对其进行转义:
Get-Date -Format "MM\/dd\/yyyy"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1743 次 |
| 最近记录: |