C#, convert time from floating-point number representation to string representation
I have a time represented as a floating-point number (in seconds). I need a function to convert this开发者_StackOverflow 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
That will be TimeSpan.FromSeconds
:
Returns a
TimeSpan
that represents a specified number of seconds, where the specification is accurate to the nearest millisecond.
精彩评论