문제

I know I can set a date to a variable in PowerShell using

$a = Get-Date

It works great, but when looking through the documentation on formatting the date, there wasn't one for MMDDYY.

How do I accomplish this?

도움이 되었습니까?

해결책

Because $a is effectively a System.DateTime. You can do:

$a = Get-Date
Write-Host $a.ToString('MMddyy')

Full details on custom Date and Time Format Strings are in Custom Date and Time Format Strings.

다른 팁

You just have to get creative with the -UFormat options. To get exactly what you want run this:

(Get-Date -UFormat %m)+(Get-Date -UFormat %d)+(Get-Date -UFormat %y)

However I think this is much easier to read:

Get-Date -UFormat %D

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top