C#,将时间从 float 表示形式转换为字符串表示形式

标签 c# algorithm

我有一个时间表示为 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/

相关文章:

c# - 可使用 IEnumerable 属性和列表成员序列化

c# - 什么时候应该使用 XML 序列化?

c# - Blazor:降低/消除图表的动画速度

c# - 从 .NET 3.5 中的 double 获取小数位的精确精度

algorithm - 如何计算一段代码的每一行的运行时间

C# StructLayout.Explicit 问题

algorithm - 有没有办法在 Perl 中检查 CUSIP 的数字

string - 句子的词级编辑距离

ios - 使用 'Shuffle Albums' 将 NSMutableArray 随机播放到下一个队列(MediaPlayer)?

algorithm - 删除连续子数组以保留平均最小值