Format TimeSpan to mm:ss for positive and negative TimeSpans

后端 未结 2 1792
猫巷女王i
猫巷女王i 2021-02-20 04:11

I\'m looking for a solution in .net 3.5 I wrote the following working solution:

private string FormatTimeSpan(TimeSpan time)
{
    return String.Format(\"{0}{1:0         


        
相关标签:
2条回答
  • 2021-02-20 04:48

    Somewhat shorter, using Custom TimeSpan Format Strings:

    private string FormatTimeSpan(TimeSpan time)
    {
        return ((time < TimeSpan.Zero) ? "-" : "") + time.ToString(@"mm\:ss");
    }
    
    0 讨论(0)
  • 2021-02-20 04:56

    for below .Net 4.0

    You can use:

    get { return Time.ToString().Substring(3); }
    
    0 讨论(0)
提交回复
热议问题