Any easy way in C# to convert seconds to H:M:S?

  • Thread starter Thread starter 00_CP_D12
  • Start date Start date
0

00_CP_D12

Is there an easy way in C# to convert seconds to Hours: Minutes: Seconds?

For example, 65 seconds will return 0 hr, 1 min, 5 secs.

Thanks...
 
Easy, in that you want to use standard classes and not do the math
yourself:

int seconds = 65;
TimeSpan span = new TimeSpan(0, 0, seconds);
int normalizedHours = span.Hours;
int normalizedMinutes = span.Minutes;
int normalizedSeconds = span.Seconds;
 
00_CP_D12,
I normally use TimeSpan.FromSeconds to convert from seconds to HMS.

For example:

double seconds = 65;
TimeSpan hms = TimeSpan.FromSeconds(seconds);

Hope this helps
Jay

| Is there an easy way in C# to convert seconds to Hours: Minutes: Seconds?
|
| For example, 65 seconds will return 0 hr, 1 min, 5 secs.
|
| Thanks...
|
|
 
Back
Top