我希望使用$ time:
的时间设置下面的System.DateTime对象$CurrentTime = (date)
$Time = "9:00"
如何从$ CurrentTime获取日期,但是从$ time开始的小时,分钟,秒?
答案 0 :(得分:5)
试试这个:
[datetime]::ParseExact("09:00","hh:mm",$null)
答案 1 :(得分:1)
这应该有效:
$CurrentTime = [System.DateTime]::Parse((date).ToString("yyyy.MM.dd"))
$Time = [System.Timespan]::Parse("9:00")
$Result = $CurrentTime.Add($Time)
答案 2 :(得分:1)
$CurrentTime = Get-Date -Hour "09" -Minute "00" -Second "00"
答案 3 :(得分:0)
Get-Date -Year $CurrentTime.Year `
-Month $CurrentTime.Month `
-Day $CurrentTime.Day `
-Hour $time.split(':')[0] `
-Minute $time.split(':')[-1]
-Second $time.split(':')[-1]