如何格式化时间范围以显示总时间? [英] How do I format a timespan to show me total hours?
问题描述
我想将用户的工作时间保存在数据库的 varchar
列中,但是默认情况下,如果小时数超过24,则格式化值包括天数.小时.
I want to save the user's hours worked in a database varchar
column, but by default, the formatted value includes days if the number of hours is more than 24. I just want the total number of hours.
例如:如果用户今天工作10:00:00小时,则明天工作13:00:00小时,后天工作3:30:00小时,则我想要的格式化总数为26:30:00.相反,我看到的是1.2:30:00.
For example: if a user works 10:00:00 hours today, then 13:00:00 hours tomorrow, and 3:30:00 hours the day after tomorrow then the formatted total I want is 26:30:00. Instead, I am seeing 1.2:30:00.
如何获取所需的格式?
另外,当我手动将值40:00:00保存在数据库中,并稍后尝试将其读入 TimeSpan
时,我遇到了一个错误.
Also, when I save the value 40:00:00 in the database manually, and try to read it into a TimeSpan
later, I get a bug.
我如何以所需的方式在数据库中节省时间,并且以后仍然可以将其读回 TimeSpan
?
How can I save the hours in the database the way I want, and still be able to read it back into a TimeSpan
later?
推荐答案
尝试
这篇关于如何格式化时间范围以显示总时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!