希望有人可以帮我一把。我无法将当前日期与创建文件的日期进行比较。我从每个日期得到的输出与我的代码一起在下面。
创建日期输出:
21/05/2012 晚上 10:27:25
当前日期输出:
2013 年 8 月 5 日上午 12:00:00
是否可以比较这些日期?
我的代码如下:
$host = Read-Host 'Host: '
$username = Read-Host 'Username: '
$password = Read-Host 'Password: '
Connect-VIServer -Server $host -User $username -Password $password
$snapshotDate = Get-Snapshot -VM CONVCORPSPOINT | Select-Object Created | Format-Table -HideTableHeaders
$currentDate = Get-Date | Select-Object Date | Format-Table -HideTableHeaders
$snapshotDate
$currentDate
if ($snapshotDate -lt $currentDate) {
Write-Host 'The snapshot date is earlier than the current date'
}
else {
Write-Host 'The snapshot date is not earlier than the current date'
}