转换时间在C#为十进制 [英] Convert Time to decimal in C#
问题描述
我需要做的,是有一个由用户输入的两个定义的字符串,
在=字符串9 :35; //上午
串出=11:55; //上午
和我需要减去他们,这样会得到总时数,他们签署其中应该等于:
字符串总=2:20
然后,我需要的转换为十进制..所以,2:20就
字符串小数=2.33;
我不知道该怎么做,任何帮助,将不胜感激!
PS:ID也希望能够来计算,他们从一个十进制数被检查的总时间,所以基本上相反
的DateTime DT1 = DateTime.Parse(11:55);
日期时间DT2 = DateTime.Parse(9:35);
双跨=(DT1 - DT2).TotalHours;
你实际需要的2:20或者是只是一个中间步骤?
编辑:如果你想回去,你只需要做的数学一点点。取小数剩余时间和乘以60,那么圆。这些将是分钟,所以只需将它们添加到小时。
what i need to do, is have two defined strings that is inputted by the user,
string in = "9:35"; //am
string out = "11:55"; //am
and i need to subtract them, so that would get the total hours that they were signed in. which should equal:
string total = "2:20"
then, i need to convert that into a decimal.. so, 2:20 would be
string decimal = "2.33";
I dont know how to do that, any help would be appreciated!
P.S: id also like to be able to calculate the total hours they were checked in from a decimal number, so basically the opposite
DateTime dt1 = DateTime.Parse("11:55");
DateTime dt2 = DateTime.Parse("9:35");
double span = (dt1 - dt2).TotalHours;
Do you actually need the "2:20" or is that just an intermediate step?
Edit: If you wanted to go back, you'd just need to do a little bit of math. Take the remainder of the decimal and multiply by 60, then round. Those will be the minutes, so just add them to the hours.
这篇关于转换时间在C#为十进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!