Powershell - Get-Date.AddDays 如何获取所需的格式

Wik*_*ski 3 powershell

我有 velow 脚本

       $AddDays = Read-Host "How long user will be active (: in Days) "
       $DateInFuture = (Get-date).AddDays($AddDays).ToString('yyyy-mm-dd')
Run Code Online (Sandbox Code Playgroud)

我想在当前日期中添加天数,但我得到了这样的东西..

“2020-57-18”

假设今天是“2020-04-18”,我添加了 5 天...如何使用这种格式添加天数?年-月-日

Eri*_*len 8

You need to change the format using inside the ToString, mm represents minutes and MM represents months

$AddDays = Read-Host "How long user will be active (: in Days) "
$DateInFuture = (Get-date).AddDays($AddDays).ToString('yyyy-MM-dd')
Run Code Online (Sandbox Code Playgroud)

This get's the desired output of 2020-04-18