![](/img/trans.png)
[英]What does it mean when there is a comma inside an array declaration? e.g. float[,]
[英]What does a Timespan mean when you get decimals in the hours. e.g. 43.02:10:00 and how do I avoid it
因此,我试图记录设备上剩余电池寿命的时间跨度
我的方法是:
PowerStatus powerStatus = SystemInformation.PowerStatus;
if (powerStatus.BatteryLifeRemaining > -1)
{
Console.WriteLine(String.Format("Battery Life Remaining {0}",new TimeSpan(0, 0, powerStatus.BatteryLifeRemaining)).ToString());
}
但是我时不时地得到奇怪的价值观,例如7.01:44:22
看一下TimeSpan构造函数
那里的例子表明:
TimeSpan( 1000, 2000, 3000 ) = 43.02:10:00
TimeSpan( 1000, -2000, -3000 ) = 40.05:50:00
TimeSpan( 999999, 999999, 999999 ) = 42372.15:25:39
但是这些值是什么意思,我如何避免获取它们,因为它们在现实世界中没有多大意义
MSDN文档对此进行了很好的解释。 小数点前的数字是天,后数是小时。
43.02:10:00
转换为:
43 days
02 hours
10 minutes
00 seconds
您可以使用以下代码进行验证:
var ts = new TimeSpan(1000, 2000, 3000);
Console.WriteLine(ts.TotalDays); // Output: 43.0902777777778
Console.WriteLine(ts.Days); // Output: 43
Console.WriteLine(ts.TotalHours); // Output: 1034.16666666667
Console.WriteLine(ts.Hours); // Output: 2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.