简单、方便、准确,让神马的 for 和 if 见鬼去吧。- $myInput = Read-Host 'Input';
- $formats = [String[]]('MM/dd', 'M/d');
- $provider = [Globalization.CultureInfo]'zh-CN';
- $style = [Globalization.DateTimeStyles]::None;
- $result = [DateTime]0;
-
- [DateTime]::TryParseExact($myInput, $formats, $provider, $style, [ref]$Result);
- [Console]::ReadLine()
复制代码 https://learn.microsoft.com/zh-cn/dotnet/api/system.datetime.tryparseexact?view=net-8.0 |