0
我想字符串变量转换为日期时间格式:ParseExact - 字符串未被识别为有效的DateTime
[DateTime]::ParseExact($tempdate, 'dd.MM.yyyy', [CultureInfo]::InvariantCulture).ToString('yyMMdd')
$tempdate
包含在其中从Excel文件格式得到日期dd.MM.yyyy
。
不幸的是我得到错误信息:
Exception calling "ParseExact" with "3" argument(s): "String was not recognized as a valid DateTime." At line:1 char:1 + [DateTime]::ParseExact($tempdate, 'dd.MM.yyyy', [CultureInfo]::Invaria ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : FormatException
,当我把“清洁日”,而不是变量,它工作正常。
[DateTime]::ParseExact('13.03.2017', 'dd.MM.yyyy', [CultureInfo]::InvariantCulture).ToString('yyMMdd')
这个变量有什么问题,或者我怎样才能以其他方式将它转换为datetime?
[这是什么在PowerShell中ParseExact代码的问题(// stackoverflow.com/q/17940647) – wOxxOm
什么是'$ tempdate'的类型和价值? –
除非我们更多地了解'$ tempdate',否则无法帮助您。 wOxxOm的链接问题有帮助吗?什么是当前类型? '$ tempdate.GetType()。Fullname'。是否有前导或尾随空格? '''$ tempdate'“' – Matt