繁体   English   中英

Powershell 转换时间

[英]Powershell convert time

我正在尝试使用 ss.ff 格式转换时间

我得到了转换,但给了我以下错误:

Cannot find an overload for "TryParseExact" and the argument count: "3".
At line:1 char:6
+      $ts = [TimeSpan]::TryParseExact('28.50 s', "ss\.ff\ s", [Culture ...
+      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest 

我的代码:

 $ts = [TimeSpan]::TryParseExact('28.50 s', "ss\.ff\ s", [CultureInfo]::InvariantCulture)
("{0:hh\:mm\:ss}" -f $ts)

$ts 变量的结果

Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 28
Milliseconds      : 500
Ticks             : 285000000
TotalDays         : 0.000329861111111111
TotalHours        : 0.00791666666666667
TotalMinutes      : 0.475
TotalSeconds      : 28.5
TotalMilliseconds : 28500

我在做什么错?

谢谢你的帮助

如果你输入

[timespan]::TryParseExact

然后按回车,你会看到所有有效的重载。 您会注意到它们都没有 3 个参数,这也是您的错误明确说明的内容。 您还可以在此处找到信息: https : //docs.microsoft.com/en-us/dotnet/api/system.timespan.parseexact?view=netcore-3.1

所以基本上你的语法是不正确的。

也许这就是你所追求的?

$ts = [timespan]::ParseExact('28.50 s','ss\.ff\ \s',[cultureinfo]::InvariantCulture)
("{0:hh\:mm\:ss}" -f $ts)

在这种情况下, $ts看起来与上面的输出完全一样。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM