timeToDecimal

Convert string time(hh:mm) in decimal

源代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
public static Decimal timeToDecimal(this string time)
{
int Hours = time.Split(':')[0].ToInt();
decimal Minutes = time.Split(':')[1].ToInt();
while (Minutes >= 60)
{
Minutes = Minutes % 60;
Hours ++;
}
//Minutes = Minutes/60;
long test = Convert.ToInt64((Minutes/60)/10);
return Hours + Minutes/60;
}

示例:

1
2
3
4
5
6
7
Convert a time string in decimal format.
decimal time = "19:70".timeToDecimal();

Some examples:
19:30 to 19.5
19:70 to 20.166666666666666666666666667
12:45 to 12.75
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×