处理负值的时间跨度 [英] Handle negative time spans

查看:191
本文介绍了处理负值的时间跨度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在网格中的我的输出

我计算时间跨度,并采取了TotalHours前。

I calculate a TimeSpan and take its TotalHours ex.

(Eval("WorkedHours") - Eval("BadgedHours")).TotalHours

目标是展示这种TotalHours为:39:44左右。首先值7.5至07:30

goal is to show this TotalHours as : 39:44 so. First value 7.5 to 07:30

没有问题..但如果​​其负面!

no problem.. but if its negative!

我可以创建一个小时时间跨度对象

I can create a TimeSpan object from Hours with

TimeSpan.FromHours( (Eval("WorkedHours") - Eval("BadgedHours")).TotalHours)

现在如果负我不能将它转换为datetime和使用的ToString(HH:MM)。方法

now if its negative i cant convert it to a datetime and use the .ToString("HH:mm") method.

和时间跨度对象不支持的格式字符串。

And the timespan object does not support the format string .

推荐答案

是不是有一个TimeSpan.Duration方法?我认为这会处理,你正在做什么。

Isn't there a TimeSpan.Duration method? I think this would handle what you are trying to do.

这篇关于处理负值的时间跨度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆