0

I receive imports from an external source where the timespan fields are stored in seconds. To convert these to a timespan I currently do this

TimeSpan.FromSeconds(140520)

This results in a timespan that displays 1 15:02:00
What I would like is that it displays 39:02:00

How can I do this ?

GuidoG
  • 11,359
  • 6
  • 44
  • 79

1 Answers1

3

The TotalHours property of the resulting TimeSpan should give you the first part of what you want:

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;
maccettura
  • 10,514
  • 3
  • 28
  • 35
  • 2
    So you are saying I should build the result myself, using the Hours property of the timestamp ? Something like timeSpan.TotalHours.ToString() + ":" + timeSpan.Minutes; ? – GuidoG Apr 05 '17 at 14:29
  • 1
    I made a working function with this info, thanks – GuidoG Apr 05 '17 at 15:11