Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#, convert time from floating-point number representation to string representation

Tags:

c#

algorithm

I have a time represented as a floating-point number (in seconds). I need a function to convert this representation to string format. Somethins like this:

    /// <summary>
    /// Get time from a float representation.
    /// </summary>
    /// <param name="f">Time in a floating-point number.</param>
    /// <returns>Time in a string format.</returns>
    string GetTime(float f)
    {
        return f.ToString(); // string format is hh:mm:ss (h-hours, m-minutes, s-seconds)
    }

For example, 10.0 converts to 00:00:10, 67.0 converts to 00:01:07

like image 613
Александр Д. Avatar asked Jan 22 '23 21:01

Александр Д.


1 Answers

That will be TimeSpan.FromSeconds:

Returns a TimeSpan that represents a specified number of seconds, where the specification is accurate to the nearest millisecond.

like image 70
Anton Gogolev Avatar answered Jan 24 '23 10:01

Anton Gogolev