下午好,
有人可以告诉我如何使用 powershell 将日期 20120624 转换为 yyyyMMdd,因为我在运行以下代码时得到“字符串未被识别为有价值的日期时间”
[String]$ServiceTag = "b26ybt1";
Try{
$AssetService = New-WebServiceProxy -Uri "http://xserv.dell.com/services/AssetService.asmx?WSDL";
$ApplicationName = "AssetService";
$Guid = [Guid]::NewGuid();
$Asset = $AssetService.GetAssetInformation($Guid,$ApplicationName,$ServiceTag);
$Writer = New-Object "System.IO.StringWriter";
$XmlSerializer = New-Object System.Xml.Serialization.XmlSerializer($Asset.GetType());
$XmlSerializer.Serialize($Writer,$Asset);
[String]$Result = $Writer.ToString();
$Writer.Flush();
$Writer.Close();
Return $Result;
}
Catch{
Write-Host $($_.Exception.Message);
}
$prog = [regex]::match($Result,'(?<=StartDate>)(.*)(?=T00)').Groups[1].Value
[System.Text.RegularExpressions.Regex]::Replace($prog,"[-]","");
[datetime]::ParseExact($prog,"yyyyMMdd",$null)