powershell - 将字符串转换为 PowerShell 日期和时间格式
问题描述
我可以使用一些帮助来确定在 PowerShell 中将字符串转换为 DateTime 的格式语法。我尝试了很多组合并继续得到
Exception calling "ParseExact" with "3" argument(s): "String was not recognized as a valid DateTime."
我尝试使用的代码如下:
$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 。有人愿意告诉我我做错了什么吗?我被困住了!非常感谢!
解决方案
试试这个,让解析器完成工作:
$timeinfo = '04/02/2020 02:00 PM'
[datetime]$timeinfo
推荐阅读
- ksqldb - 更改配置、偏移量和状态主题时,ksqlDB 服务器关闭
- python - 训练 RetinaNet 也会训练主干(ResNet)吗?
- flutter - 如何通过 Flutter 在 GridView 上制作动态高度项
- angular - Angular Uncaught ReferenceError:未定义全局
- sql - SQL:从存在多个分隔符的字符串中提取下一个字符
- salesforce - Salesforce 中用于营销云连接电子邮件的低分辨率电子邮件预览
- python - AutoMod 导致 Discord.py 出现问题
- c# - 当 .net 应用程序通过命令提示符运行时,fuslogvw 和 Fusion++ 不会记录绑定失败
- javascript - 避免强制解包选项
- python - 如何使用 Selenium 和 Python 从表中捕获隐藏数据?