[英]Convert string to PowerShell date and time format
我可以使用一些帮助来找出在 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.