Force Get-Date use '/' as date separator

How can I get Get-Date to create '/' as date separator? There is a requirement to create a US date format. It looks like PowerShell will always use the locale regardless of the format specified. It is set to "-" on my system, but I need to create a date using '/'.

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

      

The date separator is set to "-" on my machine. I don't find the Set-UICulture command.

PS C:\src> (Get-UICulture).DateTimeFormat.DateSeparator
-

      

+3


source to share


1 answer


The format string /

represents the current UICulture date separator. To force it to be explicitly a symbol /

, you must escape it with a symbol \

:



Get-Date -Format "MM\/dd\/yyyy"

      

+3


source







All Articles