2009年11月25日 星期三

C# 時間相減

            TimeSpan timekey = DateTime.Parse(06:00).Subtract(DateTime.Parse(10:15)); //時間相減
decimal a = decimal.Parse(timekey.ToString().Substring(0, 2));
decimal b = decimal.Parse(timekey.ToString().Substring(3, 2));
decimal C = a + (b / 60);

計算結果為
a = 4
b = 15
c = 4.25

沒有留言:

張貼留言