首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将字符串转换为PowerShell日期和时间格式

将字符串转换为PowerShell日期和时间格式
EN

Stack Overflow用户
提问于 2020-09-02 21:06:51
回答 1查看 53关注 0票数 0

我需要一些帮助来弄清楚在PowerShell中将字符串转换为DateTime的格式语法。我尝试了许多组合,并继续获得Exception calling "ParseExact" with "3" argument(s): "String was not recognized as a valid DateTime."

我尝试使用的代码如下:

代码语言:javascript
复制
$timeinfo = '1/‎3/‎2020 ‏‎9:56 AM'
$template = 'M/d/yyyy h:mm tt'
$culture = [Globalization.CultureInfo]::InvariantCulture
[DateTime]::ParseExact($timeinfo, $template, $culture)

我使用了我在这里找到的语法:https://community.idera.com/database-tools/powershell/powertips/b/tips/posts/parsing-custom-datetime-formats。有人愿意告诉我我哪里做错了吗?我卡住了!非常感谢!

EN

回答 1

Stack Overflow用户

发布于 2020-09-03 13:48:47

试试这个,让解析器来做这项工作:

代码语言:javascript
复制
$timeinfo = '04/02/2020 02:00 PM'

[datetime]$timeinfo
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63706181

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档