我有一个时间表示为 float (以秒为单位)。我需要一个函数来将此表示形式转换为字符串格式。像这样的东西:
/// <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)
}
例如10.0转换为00:00:10,67.0转换为00:01:07
最佳答案
那将是 TimeSpan.FromSeconds
:
Returns a
TimeSpan
that represents a specified number of seconds, where the specification is accurate to the nearest millisecond.
关于C#,将时间从 float 表示形式转换为字符串表示形式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3082652/