1

我希望使用 $time 的时间设置下面的 System.DateTime 对象:

$CurrentTime = (date)
$Time = "9:00"

如何从 $CurrentTime 获取日期,但从 $time 获取小时、分钟、秒?

4

4 回答 4

7

尝试这个:

[datetime]::ParseExact("09:00","hh:mm",$null)
于 2012-04-15T06:46:08.493 回答
1

这应该有效:

$CurrentTime = [System.DateTime]::Parse((date).ToString("yyyy.MM.dd"))
$Time = [System.Timespan]::Parse("9:00")
$Result = $CurrentTime.Add($Time)
于 2012-04-14T10:51:48.820 回答
1
Get-Date -Year $CurrentTime.Year `
         -Month $CurrentTime.Month `
         -Day $CurrentTime.Day `
         -Hour $time.split(':')[0] `
         -Minute $time.split(':')[-1]
         -Second $time.split(':')[-1]
于 2012-04-14T11:12:05.313 回答
1
$CurrentTime = Get-Date -Hour "09" -Minute "00" -Second "00"
于 2019-03-05T14:33:16.913 回答