tags:

views:

56

answers:

1

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

+6  A: 

That will be TimeSpan.FromSeconds:

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

Anton Gogolev
TimeSpan.FromSeconds(seconds).ToString(format)
simendsjo
Thanks for a quick answer !
alex