用PowerShell从字符串00:00:00获取平均值
我有一些数据要分析。一个示例是任务持续时间的列表:
$tasks.duration
00:04:44
00:00:00
00:00:05
是否有一种简单的方法可以从此列表中获取不断的持续时间?显然,您不能仅使用诸如Measure-object之类的东西,因为它是带有特殊字符的字符串。
您将如何处理此问题,为什么?
I have some data to analyse. One example is a list of durations of tasks:
$tasks.duration
00:04:44
00:00:00
00:00:05
Is there a simple way to get the avarage duration from this list? Obviously you can't just use something like Measure-Object, because it's a string with special characters.
How would you approach this and why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将字符串解析为
值,然后计算每个秒的平均秒数,将结果转回[timespan]
[timespan]
,然后最终产生正确的格式格式的字符串:在您提供的示例值的情况下,给出:
Parse the strings into
[timespan]
values, then calculate the average number of seconds in each, turn the result back into a[timespan]
and then finally produce a correctly formatted string:Which, with the sample values you've provided, gives: