2017-04-05 81 views
0

我接收來自外部源的輸入,其中時間跨度字段以秒爲單位進行存儲。 來將這些轉換爲時間跨度我目前做這個如何顯示累積時間的TimeSpan?

TimeSpan.FromSeconds(140520) 

這導致顯示1 15:02:00
我想什麼時間跨度的是,它顯示39:02:00

我怎樣才能做到這一點?

+1

重複的是確切的東西我一直在尋找,謝謝 – GuidoG

回答

3

所產生的時間跨度的TotalHours物業應該給你你想要什麼第一部分:

var timespan = TimeSpan.FromSeconds(140520); 
//If you cast the TotalHours to int you will get '39' 
int totalHours = (int)timespan.TotalHours; 

//If you want the '2' that would result from your input of 140520 you will need the minutes property 
int minutes = timespan.Minutes; 
+2

所以你說我應該建立結果自己,使用時間戳的Hours屬性?像timeSpan.TotalHours.ToString()+「:」+ timeSpan.Minutes; ? – GuidoG

+1

我用這個信息做了一個工作函數,謝謝 – GuidoG