Powershell 关于[DateTime]:ParseExact(),我没有得到什么?

Powershell 关于[DateTime]:ParseExact(),我没有得到什么?,powershell,datetime,exception,format,Powershell,Datetime,Exception,Format,结果: $timeinfo = "01-‎06‎-2017 ‏‎12:34" $template = "dd-MM-yyyy HH:mm" [DateTime]::ParseExact($timeinfo, $template, $null) 使用“3”参数调用“ParseExact”时出现异常:“无法识别字符串。” 作为有效的日期时间。” 第3行字符:1 +[日期时间]::ParseExact($timeinfo,$template,$null) + ~~~~~~~~~~~~~~~~~~~~

结果:

$timeinfo = "01-‎06‎-2017 ‏‎12:34"
$template = "dd-MM-yyyy HH:mm"
[DateTime]::ParseExact($timeinfo, $template, $null)
使用“3”参数调用“ParseExact”时出现异常:“无法识别字符串。” 作为有效的日期时间。” 第3行字符:1 +[日期时间]::ParseExact($timeinfo,$template,$null) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +CategoryInfo:NotSpecified:(:)[],MethodInvocationException +FullyQualifiedErrorId:FormatException
我不知道这里出了什么问题?当我在模板中指定如何读取字符串时,为什么我的字符串不是有效的日期时间?

您的
$timeinfo
变量中有一些奇怪的字符。复制和粘贴时,我得到以下信息:

您可以通过按向右或向左箭头并遍历字符串来查看这一点;它在奇数字符处暂停

更改为
$timeinfo=“01-06-2017 12:34”
,您的代码将按预期工作。复制并粘贴此字符串以进行测试


编辑-使用,看起来这是

您可能复制并粘贴了代码,因为
$timedate
中有不正确的字符,请尝试复制并粘贴:

Exception calling "ParseExact" with "3" argument(s): "String was not recognized as a valid DateTime." At line:3 char:1 + [DateTime]::ParseExact($timeinfo, $template, $null) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : FormatException
@用户3272783没问题-这让我以前在证书指纹中发现了问题。如果您感兴趣,请添加更多信息以回答。如果你觉得答案很有帮助的话!如何使用脚本中的函数从字符串中删除这些奇怪的字符?
$timeinfo = "01-06-2017 12:34"
$template = "dd-MM-yyyy HH:mm"
[DateTime]::ParseExact($timeinfo, $template, $null)