我对[DateTime] :: ParseExact()没有什么了解? [英] What am I not getting about [DateTime]::ParseExact()?

查看:64
本文介绍了我对[DateTime] :: ParseExact()没有什么了解?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$timeinfo = "01-‎06‎-2017 ‏‎12:34"
$template = "dd-MM-yyyy HH:mm"
[DateTime]::ParseExact($timeinfo, $template, $null)

导致:


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

我不知道这里出什么问题了吗?当我在模板中指定应如何读取字符串时,为什么我的字符串不是有效的日期时间?

I can't tell what is wrong here? Why is my string not a valid datetime when I specify in the template how it should read it?

推荐答案

在您的 $ timeinfo 变量中,您有一些奇怪的字符.复制和粘贴时,出现以下提示:

You have some strange characters in your $timeinfo variable. When copying and pasting, I am getting this:

您可以通过按向右或向左箭头并遍历字符串来查看此内容;它会停在奇数字符处.

You can see this by pressing the right or left arrow and going through the string; it pauses at the odd character.

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

Changing to $timeinfo = "01-06-2017 12:34", your code works as expected. Copy and paste this string to test.

编辑-使用 Unicode转换器,它看起来像这是 LRM控制字符

Edit - Using a Unicode converter, it looks like this is LRM control character

这篇关于我对[DateTime] :: ParseExact()没有什么了解?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆